.NET trace does not work with Diagnostics.TraceSource, only Diagnostics.Trace

I am trying to configure .NET trace. I can get the base trace for working through System.Diagnostics.Trace, but for complex reasons I need to activate the trace through System.Diagnostics.TraceSource objects (a new way to do this, starting with .NET 2.0), and not use System.Diagnostics.Trace . I tried everything, but it just doesn't want to work using TraceSource. I am tracing in ASP.NET code (aspx.cs)

Here are some 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 track both the file and the page based on 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(); 

The web.config sections make sense:

  <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 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"/> 
+5
c # web-config trace
Sep 29 '10 at 15:07
source share
1 answer

change switchName="mySwitch" to switchValue="Verbose" . Then it outputs ALL tracks through the tracing source. You can modify switchLevel to increase / decrease trace verbosity. In your example, you have traced an informational message, there is, detailed, information, warnings, error, critical. Set the switch to a warning and you will not receive any detailed or informational messages.

+5
Nov 25 '10 at 23:15
source share



All Articles