System.Diagnostics.DefaultTraceListener Class

Provides the default output methods and behavior for tracing.

See Also: DefaultTraceListener Members


public class DefaultTraceListener : TraceListener


An instance of this class is automatically added to the Debug.Listeners and Trace.Listeners collections. Explicitly adding a second System.Diagnostics.DefaultTraceListener causes duplicate messages in the debugger output window and duplicate message boxes for asserts.

By default, the DefaultTraceListener.Write(string) and DefaultTraceListener.WriteLine(string) methods emit the message to the Win32 OutputDebugString function and to the Debugger.Log(int, string, string) method. For information about the OutputDebugString function, see the Platform SDK or MSDN.

The DefaultTraceListener.Fail(string) method, by default, displays a message box when the application is running in a user interface mode; it also emits the message using DefaultTraceListener.WriteLine(string).


The display of the message box for erload:System.Diagnostics.Debug.Assert and erload:System.Diagnostics.Debug.Fail method calls depends on the presence of the System.Diagnostics.DefaultTraceListener. If the System.Diagnostics.DefaultTraceListener is not in the Trace.Listeners collection, the message box is not displayed. The System.Diagnostics.DefaultTraceListener can be removed by the <clear> element, by the <remove> element, or by calling the TraceListenerCollection.Clear method on the Trace.Listeners property (System.Diagnostics.Trace.Listeners.Clear()).

You must enable tracing or debugging to use a trace listener. The following syntax is compiler specific. If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.

To add a trace listener, edit the configuration file that corresponds to the name of your application. Within this file, you can add a listener, set its type and set its parameters, remove a listener, or clear all the listeners previously set by the application. The configuration file should be formatted similar to the following example:


  <trace autoflush="false" indentsize="4">
      <remove name="Default" />
      <add name="myListener"  type="System.Diagnostics.TextWriterTraceListener"    initializeData="c:\myListener.log" />


Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,,