Diagnostics, where to read the Trace.TraceInformation?

8.4k views Asked by At
Trace.AutoFlush = true;
Trace.TraceInformation(string.Format("Try starting: {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName()));
Trace.Flush();

I have read: How to Check the Application Event Log for Errors

But I can not find any traces! What am I doing wrong?

1

There are 1 answers

4
AudioBubble On BEST ANSWER

The Trace can output to multiple listeners.

These can include debug (visual studio), file and even database listeners.

By default the Trace outputs to the Visual Studio output window.

This article describes how to configure a file trace listener: How to: Create and Initialize Trace Listeners

The System.Diagnostics.Debug and System.Diagnostics.Trace classes send messages to objects called listeners that receive and process these messages. One such listener, the System.Diagnostics.DefaultTraceListener, is automatically created and initialized when tracing or debugging is enabled. If you want Trace or Debug output to be directed to any additional sources, you must create and initialize additional trace listeners.

Via the app.config:

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

Or via code:

Trace.Listeners.Add(new TextWriterTraceListener("TextWriterOutput.log", "myListener"));

If you want to log to the Event Log then you can use the Event Log Trace Listener.