System.Diagnostics.TextWriterTraceListener Class

Directs tracing or debugging output to a System.IO.TextWriter or to a System.IO.Stream, such as System.IO.FileStream.

See Also: TextWriterTraceListener Members

Syntax

public class TextWriterTraceListener : TraceListener

Remarks

The System.Diagnostics.TextWriterTraceListener class provides the TextWriterTraceListener.Writer property to get or set the text writer that receives the tracing or debugging output.

This class also provides methods to TextWriterTraceListener.Close the TextWriterTraceListener.Writer so that it no longer receives tracing or debugging output, to TextWriterTraceListener.Flush the output buffer for the TextWriterTraceListener.Writer, and to TextWriterTraceListener.Write(string) a message to the TextWriterTraceListener.Writer.

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 parameter, remove a listener, or clear all the listeners previously set by the application. The configuration file should be formatted like the following example.

Example

<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>
Note:

If an attempt is made to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID.

Requirements

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