.NET 4.0 Tracing; Problems using TraceSwitch

I am trying to set up .NET tracing in my C # application. I was able to set up a tracking application in the console and a .log file. But I am unable to set it up correctly TraceSwitch

.

I am using a System.Diagnostics.Trace

tracing class . I read this post which I should be using instead for logging / tracing. Is there an easy way to implement a "new way of tracking" (post .NET 2.0)? Or do I need to write my own Trace class that uses and provides functionality such as "old tracing (pre 2.0)" - for example ? TraceSource

Diagnostics.Trace

TraceSource

Trace.TraceInformation("my msg")

Here's my App.config file:

<!-- Trace Sources -->
<sources>
  <source name="MySource" switchName="AppTraceLevel"> <!-- switchValue="Off" does not work either -->
    <listeners>
      <add name="ConsoleTraceListener" />
      <add name="LogTraceListener" />
      <remove name="Default"  />
    </listeners>
  </source>
</sources>

<!-- Trace Level -->
<switches>
  <add name="AppTraceLevel" value="Off"/>
</switches>

<!-- Trace Listeners -->
<sharedListeners>
  <add name="ConsoleTraceListener"
       type="System.Diagnostics.ConsoleTraceListener"
       initializeData="false"
       traceOutputOptions="ProcessId, DateTime" />
  <add name="LogTraceListener"
       type="System.Diagnostics.TextWriterTraceListener"
       initializeData="MyAppName.log" />
</sharedListeners>

<!-- Trace Options -->
<trace autoflush="true" indentsize="4">
  <listeners>
    <add name="ConsoleTraceListener" />
    <add name="LogTraceListener" />
  </listeners>
</trace>

      

+3


source to share





All Articles