【发布时间】:2010-09-29 15:07:35
【问题描述】:
我正在尝试设置 .NET 跟踪。我可以通过 System.Diagnostics.Trace 进行基本跟踪,但由于复杂的原因,我必须通过 System.Diagnostics.TraceSource 对象(从 .NET 2.0 开始的新方法)而不是使用 System 来激活跟踪.诊断.跟踪。我已经尝试了所有方法,但它只是不想使用 TraceSource。我在 ASP.NET 代码隐藏 (aspx.cs) 中执行跟踪
以下是一些相关的网址:
http://msdn.microsoft.com/en-us/library/ty48b824.aspx
http://msdn.microsoft.com/en-us/library/64yxa344.aspx
http://msdn.microsoft.com/en-us/library/sk36c28t.aspx
http://blogs.msdn.com/b/bclteam/archive/2005/03/15/396431.aspx
http://msdn.microsoft.com/en-us/library/b0ectfxd%28v=VS.100%29.aspx
目前,根据 web.config 中的内容,它应该从以下代码跟踪文件和页面:
TraceSource ts = new TraceSource("mysource", SourceLevels.All);
Trace.Write("Trace (old way)"); // this one works
ts.TraceInformation("Trace (new way)"); // this one doesn't work
ts.Flush();
ts.Close();
以下是相关的 web.config 部分:
<system.diagnostics>
<trace autoflush="false">
<listeners> <!-- these listeners activate the "old way" of tracing. -->
<add name="pagelistener" />
<add name="filelistener" />
</listeners>
</trace>
<sources>
<source name="mysource" switchName="myswitch">
<listeners> <!-- these listeners activate the "new way" -->
<add name="pagelistener" />
<add name="filelistener" />
</listeners>
</source>
</sources>
<sharedListeners>
<!-- these are the actual trace listeners -->
<add
name="filelistener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="loplog.txt"
/>
<add
name="pagelistener"
traceOutputOptions="none"
type="System.Web.WebPageTraceListener, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
/>
</sharedListeners>
<switches>
<!-- the sources above use this verbose switch -->
<add name="myswitch" value="Verbose"/>
</switches>
</system.diagnostics>
<system.codedom>
<!-- this compilers section should not be needed because I added
#define TRACE to the .aspx.cs file, however I put this in
since it's still not working. -->
<compilers>
<compiler
language="c#;cs;csharp"
extension=".cs"
compilerOptions="/d:TRACE"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
warningLevel="1"
/>
</compilers>
</system.codedom>
<system.web>
<!-- this trace tag should be redundant because I added trace="true" to the aspx file,
but I put it in here anyway because this wasn't working. -->
<trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="true" requestLimit="50" localOnly="true"/>
【问题讨论】:
-
在我的 ASP.NET Web 服务 (ASMX) 中,我遇到了完全相同的问题。就我而言,我在我的 ASMX 代码隐藏的顶部添加了
#define TRACE,然后它就起作用了。我看到您也在尝试定义 TRACE 标志,所以我不确定发生了什么。
标签: c# .net asp.net web-config trace