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> <add name="pagelistener" /> <add name="filelistener" /> </listeners> </trace> <sources> <source name="mysource" switchName="myswitch"> <listeners> <add name="pagelistener" /> <add name="filelistener" /> </listeners> </source> </sources> <sharedListeners> <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> <add name="myswitch" value="Verbose"/> </switches> </system.diagnostics> <system.codedom> <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> <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="true" requestLimit="50" localOnly="true"/>
eeeeaaii Sep 29 '10 at 15:07 2010-09-29 15:07
source share