Configuring a trace listener

Mostly for my own reference, here’s an example of how to configure a trace listener that writes events to a text file:

<configuration>
  ...
  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add name="TestTrace" type="System.Diagnostics.TextWriterTraceListener"
            initializeData="trace.txt" />
      </listeners>
    </trace>
   </system.diagnostics>
  ...
</configuration>

After that, all calls to System.Diagnostics.Trace.Write* functions are logged to the textfile. Example:

Trace.WriteLine("Something happened...");

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.