加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 在Global.asax中使用Trace

发布时间:2020-12-16 06:58:58 所属栏目:asp.Net 来源:网络整理
导读:我很难输出通过Global.asax中的Trace.WriteLine写入的消息,它们不会出现在Trace.axd中. 我已经添加了一个WebPageTraceListener和一个TextWriterTraceListener,如文档here所示,但我看到的只是您在跟踪中看到的正常页面事件. 我是否错过了一个步骤,以便将Globa
我很难输出通过Global.asax中的Trace.WriteLine写入的消息,它们不会出现在Trace.axd中.

我已经添加了一个WebPageTraceListener和一个TextWriterTraceListener,如文档here所示,但我看到的只是您在跟踪中看到的正常页面事件.

我是否错过了一个步骤,以便将Global.asax中写入的跟踪消息写入文件/跟踪日志?我在Application_AuthenticateRequest事件中做了一些日志记录.

解决方法

您是否使用TRACE开关进行编译或更新web.config以自动执行此操作?

从您链接到的MSDN页面(强调我的):

Although ASP.NET displays trace messages whenever tracing is enabled
for a page,System.Diagnostics trace messages are written only when
the code in which the trace messages reside is compiled by using an
explicit compiler switch—the TRACE switch
. In other words,if you do
not explicitly compile the AuthorClass using the TRACE switch,you
will not see the trace messages,even with the WebPageTraceListener
added.

You can configure your application to automatically compile using the
TRACE switch,by adding a new section to your Web.config file.

这是应放在< system.diagnostics>之后的Web.config条目.部分:

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" 
              extension=".cs" 
              compilerOptions="/d:TRACE"
              type="Microsoft.CSharp.CSharpCodeProvider,System,Version=2.0.3500.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" warningLevel="1" />
    <compiler language="VB"
              extension=".vb" 
              compilerOptions="/d:Trace=true"
              type="Microsoft.VisualBasic.VBCodeProvider,Version=1.0.5000.0,PublicKeyToken=b77a5c561934e089" />
  </compilers>
</system.codedom>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读