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


public class TextWriterTraceListener : TraceListener


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.


    <trace autoflush="false" indentsize="4">
        <add name="myListener" 
          initializeData="TextWriterOutput.log" />
        <remove name="Default" />

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.


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