Mono Class Library: System.Diagnostics Namespace

System.Diagnostics.TraceListener Class

Diagnostic message handler. [Edit]

See Also: TraceListener Members

System.Object
     System.MarshalByRefObject
          System.Diagnostics.TraceListener

public abstract class TraceListener : MarshalByRefObject, IDisposable

Remarks

Instances of the TraceListener class are used by the System.Diagnostics.Debug and System.Diagnostics.Trace classes for handling diagnostic (trace) messages.

TraceListeners can be managed either through application code, or through the application .config file, by using the (XPath) /configuration/system.diagnostics/trace/listeners and related elements.

To manage TraceListeners in the .config file:

The application .config file can also be used to set the default values of the Trace.AutoFlush and Trace.IndentSize properties on the System.Diagnostics.Debug and System.Diagnostics.Trace classes, by setting the autoflush and indentsize attributes on the (XPath) /configuration/system.diagnostics/trace element.

A sample .config file setting all of these elements:

Application .config file Example
<configuration>
  <system.diagnostics>
    <!-- Turns off System.Diagnostics.Trace.AutoFlush and 
        sets System.Diagnostics.Trace.TraceListener.IndentSize to 8. -->
    <trace autoflush="false" indentsize="8">
      <listeners>
        <!-- Add the "foo" TraceListener -->
        <add name="foo" 
          type="System.Diagnostics.TextWriterTraceListener, System"
          initializeData="some-file.txt"/>
        <!-- Remove the TraceListener we just added -->
        <remove name="foo"/>
        <!-- Remove all TraceListeners.  This also removes the DefaultTraceListener -->
        <clear/>
        <!-- Add the DefaultTraceListener back. -->
        <add name="Default"
          type="System.Diagnostics.DefaultTraceListener, System"/>
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

Note: The string specified in the type attribute will need to be a fully-qualified class name to operate properly with shared assemblies. More specifically, "System.Diagnostics.TextWriterTraceListener, System" will not work on .NET, as that is the fully-qualified class name for a private assembly, not the public/shared assemby part of .NET. Instead, .NET requires "System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

[Edit]

Requirements

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