本文介绍了.NET跟踪不工作Diagnostics.TraceSource,只有Diagnostics.Trace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图建立.NET跟踪。我能够得到基本的跟踪通过System.Diagnostics.Trace工作,但对于复杂的原因,我必须激活通过System.Diagnostics.TraceSource对象追踪(做它的新方式,因为.NET 2.0)而不是使用系统.Diagnostics.Trace。我用尽了一切办法,但它只是不希望使用TraceSource工作。我在一个ASP.NET $ C $进行跟踪C-背后(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 /库/ b0ectfxd%28V = VS.100%29.aspx

目前,基于什么是在web.config中,它应该是既跟踪对文件和页面,从该code:

  TraceSource TS =新TraceSource(MYSOURCE,SourceLevels.All);
Trace.Write(跟踪(老办法)); //这个作品
ts.TraceInformation(跟踪(新路)); //这个不起作用
ts.Flush();
ts.Close();
 

下面是web.config中相关章节:

 < System.Diagnostics程序>
       <跟踪自动冲洗=假>
            <听众> <! - 这些听众激活跟踪的老办法。 - >
                 <添加名称=pagelistener/>
                 <添加名称=filelistener/>
            < /听众>
       < /跟踪>

       <源>
            <信源名=MYSOURCE交换机名称=是myswi​​tch>
                 <听众> <! - 这些听众激活新路 - >
                       <添加名称=pagelistener/>
                       <添加名称=filelistener/>
                 < /听众>
            < /源>
       < /来源>


       < sharedListeners>
            <! - 这些都是实际的跟踪监听器 - >
            <添加
                  NAME =filelistener
                 TYPE =System.Diagnostics.TextWriterTraceListener
                 initializeData =loplog.txt
                 />
            <添加
                 NAME =pagelistener
                 traceOutputOptions =无
                 TYPE =System.Web.WebPageTraceListener,System.Web程序,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a
                 />
       < / sharedListeners>

       <开关>
            <! - 上面使用的音源这种冗长的开关 - >
            <添加名称=是myswi​​tch值=松散/&G​​T;
       < /开关>

 < /system.diagnostics>
 <系统codeDOM>
       <! - 这个编译器部分应该没有必要,因为我加了
                 将#define TRACE到.aspx.cs文件,但是我把这个
                 因为它仍然没有工作。 - >

       <编译器>
            <编译
                            语言=C#; CS; CSHARP
                            延长=CS
                            compilerOptions =/ D:TRACE
                            TYPE =Microsoft.CSharp.CSharp codeProvider,系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089
                            warningLevel =1
                            />
       < /编译器>
 < /system.$c$cdom>

 <的System.Web>
       <  - !因为我加了一丝=真到aspx文件此跟踪标记应该是多余的,
                 但我把它放在这里呢,因为这是行不通的。 - >
       <跟踪writeToDiagnosticsTrace =真正的启用=真正的pageOutput =真正的requestLimit =50设置LocalOnly =真/>
 

解决方案

变更交换机名称=是myswi​​tch switchValue =松散。这就通过tracesource输出的所有痕迹。您可以更改 switchLevel 增大/减小跟踪的详细程度。在您的样品已跟踪的信息消息,有,详细,信息,警告,错误,严重。将开关设置警告,你不会得到任何详细信息的消息。

I’m trying to set up .NET tracing. I’m able to get basic tracing to work via System.Diagnostics.Trace, but for complicated reasons I have to activate tracing via System.Diagnostics.TraceSource objects (the new way of doing it, since .NET 2.0) rather than using System.Diagnostics.Trace. I've tried everything but it just doesn't want to work using TraceSource. I am performing the tracing in an ASP.NET code-behind (aspx.cs)

Here are some related URLs:

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

Currently, based on what is in web.config, it should be tracing both to a file and to the page, from this code:

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();

Here’s the web.config sections that are relevant:

 <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"/>
解决方案

change switchName="mySwitch" to switchValue="Verbose". This then outputs ALL traces via tracesource. You can change the switchLevel to increase / reduce the verbosity of the tracing. In your sample you have traced an information message, there is, verbose, information, warnings, error, critical. Set switch to warning and you won't get any verbose or information messages.

这篇关于.NET跟踪不工作Diagnostics.TraceSource,只有Diagnostics.Trace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:26