gpt4 book ai didi

c# - .NET 跟踪不适用于 Diagnostics.TraceSource,仅适用于 Diagnostics.Trace

转载 作者:太空狗 更新时间:2023-10-29 21:42:02 28 4
gpt4 key购买 nike

我正在尝试设置 .NET 跟踪。我可以通过 System.Diagnostics.Trace 进行基本跟踪,但由于复杂的原因,我必须通过 System.Diagnostics.TraceSource 对象激活跟踪(自 .NET 2.0 以来的新方法)而不是使用 System .Diagnostics.Trace.我已经尝试了一切,但它就是不想使用 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"/>

最佳答案

switchName="mySwitch" 更改为 switchValue="Verbose"。然后通过 tracesource 输出所有跟踪。您可以更改 switchLevel 以增加/减少跟踪的详细程度。在您的示例中,您跟踪了一条信息消息,其中包含详细、信息、警告、错误、严重。将开关设置为警告,您将不会收到任何详细信息或信息性消息。

关于c# - .NET 跟踪不适用于 Diagnostics.TraceSource,仅适用于 Diagnostics.Trace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3822941/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com