System.Diagnostics.TextWriterTraceListener Class

Assembly: System.dll
Namespace: System.Diagnostics
Summary
Directs tracing or debugging output to a TextWriter or to a Stream, such as Console.Out or FileStream.
C# Syntax:
public class TextWriterTraceListener : TraceListener
Remarks
The TextWriterTraceListener class provides the TextWriterTraceListener.Writer property to get or set the text writer that receives the tracing or debugging output.

This class also provide 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 a message to the TextWriterTraceListener.Writer.

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

To set the level of your 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:

          <configuration>
          <system.diagnostics>
              <switches>
                  <add name="MagicTraceSwitch" value="3" />
              </switches>
              <trace autoflush="false" indentsize="4">
                  <listeners>
                     <add name="myListener" type="System.Diagnostics.TextWriterTraceListener,System" initializeData="c:\myListener.log" />
                     <remove type="System.Diagnostics.DefaultTraceListener,System"/> 
                  </listeners>
              </trace>
          </system.diagnostics>
          </configuration>
        
Example
The following example implements two instances of the TextWriterTraceListener class. The first instance, myTextListener , uses a StreamWriter called myOutputWriter to write to a file named TestFile.txt . The second instance, myWriter , outputs to the console screen.

First the example creates a file for output. Then it creates the StreamWriter for the first text writer, assigns it the output file, and adds it to the Trace.Listeners. Next it creates the second text writer, which it also add to the Trace.Listeners. Then, the code outputs one line of text to the file and the console screen, and two lines to the console screen. Finally, the example flushes the output buffer and closes the buffer.

After running this sample, you can open the TestFile.txt file to see the output.

public static int Main(string[] args) {
    // Create a file for output named TestFile.txt.
    Stream myFile = File.Create("TestFile.txt");
 
    /* Create a new text writer using the output stream, and add it to
     * the trace listeners. */
    TextWriterTraceListener myTextListener = new 
       TextWriterTraceListener(myFile);
    Trace.Listeners.Add(myTextListener);
 
    /* Create a text writer that writes to the console screen, and add
     * it to the trace listeners */
    TextWriterTraceListener myWriter = new 
       TextWriterTraceListener(System.Console.Out);
    Trace.Listeners.Add(myWriter);
 
    // Write output to the file and to the console screen.
    Trace.Write("Test output ");
 
    // Write only to the console screen.
    myWriter.WriteLine("Write only to the console screen.");
 
    // Flush and close the output.
    myWriter.Flush();
    myWriter.Close();
 
    return 0;
 }


    
See also:
System.Diagnostics Namespace | TraceListener | DefaultTraceListener | EventLogTraceListener | Stream | TextWriter | Debug | Trace

System.Diagnostics.TextWriterTraceListener Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the TextWriterTraceListener class with TextWriter as the output recipient.
ctor #2 Overloaded:
.ctor(Stream stream)

Initializes a new instance of the TextWriterTraceListener class, using the stream as the recipient of the debugging and tracing output.
ctor #3 Overloaded:
.ctor(string fileName)

Initializes a new instance of the TextWriterTraceListener class, using the file as the recipient of the debugging and tracing output.
ctor #4 Overloaded:
.ctor(TextWriter writer)

Initializes a new instance of the TextWriterTraceListener class using the specified writer as recipient of the tracing or debugging output.
ctor #5 Overloaded:
.ctor(Stream stream, string name)

Initializes a new instance of the TextWriterTraceListener class with the specified name, using the stream as the recipient of the debugging and tracing output.
ctor #6 Overloaded:
.ctor(string fileName, string name)

Initializes a new instance of the TextWriterTraceListener class with the specified name, using the file as the recipient of the debugging and tracing output.
ctor #7 Overloaded:
.ctor(TextWriter writer, string name)

Initializes a new instance of the TextWriterTraceListener class with the specified name, using the specified writer as recipient of the tracing or debugging output.
Public Properties
IndentLevel
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.IndentLevel


Gets or sets the indent level.
IndentSize
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.IndentSize


Gets or sets the number of spaces in an indent.
Name
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.Name


Gets or sets a name for this TraceListener.
Writer Read-write

Gets or sets the text writer that receives the tracing or debugging output.
Public Methods
Close Overridden:
Closes the TextWriterTraceListener.Writer so that it no longer receives tracing or debugging output.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
Dispose
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Dispose()

See base class member description: System.Diagnostics.TraceListener.Dispose


Releases all resources used by the TraceListener.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
Fail
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Fail(string message)

See base class member description: System.Diagnostics.TraceListener.Fail


Emits an error message to the listener you create when you implement the TraceListener class.
Fail
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Fail(string message, string detailMessage)

See base class member description: System.Diagnostics.TraceListener.Fail


Emits an error message, and a detailed error message to the listener you create when you implement the TraceListener class.
Flush Overridden:
Flushes the output buffer for the TextWriterTraceListener.Writer.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Write
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Write(object o)

See base class member description: System.Diagnostics.TraceListener.Write


Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
Write Overloaded:
Write(string message)

Overridden:
Writes a message to this instance's TextWriterTraceListener.Writer.
Write
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Write(object o, string category)

See base class member description: System.Diagnostics.TraceListener.Write


Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
Write
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Write(string message, string category)

See base class member description: System.Diagnostics.TraceListener.Write


Writes a category name and a message to the listener you create when you implement the TraceListener class.
WriteLine
(inherited from System.Diagnostics.TraceListener)
Overloaded:
WriteLine(object o)

See base class member description: System.Diagnostics.TraceListener.WriteLine


Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
WriteLine Overloaded:
WriteLine(string message)

Overridden:
Writes a message to this instance's TextWriterTraceListener.Writer followed by a line terminator. The default line terminator is a carriage return followed by a line feed (\r\n).
WriteLine
(inherited from System.Diagnostics.TraceListener)
Overloaded:
WriteLine(object o, string category)

See base class member description: System.Diagnostics.TraceListener.WriteLine


Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
WriteLine
(inherited from System.Diagnostics.TraceListener)
Overloaded:
WriteLine(string message, string category)

See base class member description: System.Diagnostics.TraceListener.WriteLine


Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.
Protected Properties
NeedIndent
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.NeedIndent


Gets or sets a value indicating whether to indent the output.
Protected Methods
Dispose Overloaded:
Dispose(bool disposing)

Overridden:
Disposes this TextWriterTraceListener object.
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
WriteIndent
(inherited from System.Diagnostics.TraceListener)
See base class member description: System.Diagnostics.TraceListener.WriteIndent


Writes the indent to the listener you create when you implement this class, and resets the TraceListener.NeedIndent property to false.

Hierarchy:


System.Diagnostics.TextWriterTraceListener Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the TextWriterTraceListener class with TextWriter as the output recipient.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public TextWriterTraceListener();
Remarks
This contructor uses the TextWriter stream as the recipient of the tracing or debugging output. Its TraceListener.Name is initialized to "TextWriter".
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the TextWriterTraceListener class, using the stream as the recipient of the debugging and tracing output.
C# Syntax:
public TextWriterTraceListener(
   Stream stream
);
Parameters:

stream

A Stream that represents the stream the TextWriterTraceListener writes to. A Stream that represents the stream the TextWriterTraceListener writes to.

Exceptions
Exception Type Condition
ArgumentNullException The stream is null.
Remarks
This constructor initializes the TraceListener.Name property to an empty string ("").
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the TextWriterTraceListener class, using the file as the recipient of the debugging and tracing output.
C# Syntax:
public TextWriterTraceListener(
   string fileName
);
Parameters:

fileName

The name of the file the TextWriterTraceListener writes to. The name of the file the TextWriterTraceListener writes to.

Exceptions
Exception Type Condition
ArgumentNullException The file is null.
Remarks
This constructor initializes the TraceListener.Name property to an empty string ("").
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of the TextWriterTraceListener class using the specified writer as recipient of the tracing or debugging output.
C# Syntax:
public TextWriterTraceListener(
   TextWriter writer
);
Parameters:

writer

A TextWriter that receives the output from the TextWriterTraceListener. A TextWriter that receives the output from the TextWriterTraceListener.

Exceptions
Exception Type Condition
ArgumentNullException The writer is null.
Remarks
This constructor initializes the TraceListener.Name property to an empty string ("").
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded ctor #5
Summary
Initializes a new instance of the TextWriterTraceListener class with the specified name, using the stream as the recipient of the debugging and tracing output.
C# Syntax:
public TextWriterTraceListener(
   Stream stream,
   string name
);
Parameters:

stream

A Stream that represents the stream the TextWriterTraceListener writes to. A Stream that represents the stream the TextWriterTraceListener writes to.

name

The name of the new instance.

Exceptions
Exception Type Condition
ArgumentNullException The stream is null.
Remarks
This constructor initializes the TraceListener.Name property to the name parameter or to an empty string (""), if the name parameter is null.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded ctor #6
Summary
Initializes a new instance of the TextWriterTraceListener class with the specified name, using the file as the recipient of the debugging and tracing output.
C# Syntax:
public TextWriterTraceListener(
   string fileName,
   string name
);
Parameters:

fileName

The name of the file the TextWriterTraceListener writes to. The name of the file the TextWriterTraceListener writes to.

name

The name of the new instance.

Exceptions
Exception Type Condition
ArgumentNullException The stream is null.
Remarks
This constructor initializes the TraceListener.Name property to the name parameter or to an empty string (""), if the name parameter is null.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded ctor #7
Summary
Initializes a new instance of the TextWriterTraceListener class with the specified name, using the specified writer as recipient of the tracing or debugging output.
C# Syntax:
public TextWriterTraceListener(
   TextWriter writer,
   string name
);
Parameters:

writer

A TextWriter that receives the output from the TextWriterTraceListener. A TextWriter that receives the output from the TextWriterTraceListener.

name

The name of the new instance.

Exceptions
Exception Type Condition
ArgumentNullException The writer is null.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Property: IndentLevel (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.IndentLevel

Summary
Gets or sets the indent level.
C# Syntax:
public int IndentLevel {get; set;}
Remarks
This property is stored on per-thread/per-request basis.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: IndentSize (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.IndentSize

Summary
Gets or sets the number of spaces in an indent.
C# Syntax:
public int IndentSize {get; set;}
Remarks
The property is stored on per-thread/per-request basis.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: Name (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.Name

Summary
Gets or sets a name for this TraceListener.
C# Syntax:
public virtual string Name {get; set;}
Remarks
The name can be used to organize and access listeners in a TraceListenerCollection collection.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: NeedIndent (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.NeedIndent

Summary
Gets or sets a value indicating whether to indent the output.
C# Syntax:
protected bool NeedIndent {get; set;}
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: Writer (read-write)
Summary
Gets or sets the text writer that receives the tracing or debugging output.
C# Syntax:
public TextWriter Writer {get; set;}
Example
The following example creates a TextWriterTraceListener that writes to the console screen. Then the code adds the new trace listener to the Trace.Listeners in the trace class.

 TextWriterTraceListener myWriter = new TextWriterTraceListener();
    myWriter.Writer = System.Console.Out;
    Trace.Listeners.Add(myWriter);
    

    
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overridden Method: Close()
Summary
Closes the TextWriterTraceListener.Writer so that it no longer receives tracing or debugging output.
C# Syntax:
public override void Close();
Remarks
If you want to send debugging or tracing output to a TextWriterTraceListener.Writer after a call to this method, you must reinitialize the TextWriterTraceListener.Writer.
Example
The following example implements a TextWriterTraceListener named myTextListener , which uses a StreamWriter called myOutputWriter to write to a file named TestFile.txt . The example creates the file, stream, and text writer, writes one line of text to the file, and then flushes and closes the stream.
public static void Main(string[] args) {
    // Create a file for output named TestFile.txt.
    String myFileName = "TestFile.txt";
    if(!File.Exists(myFileName)) {
       Stream myFile = File.Create(myFileName);
       // If the file cannot be created, exit the application.
       if(myFile == null) {
          Console.WriteLine("Could not create file");
          Application.Exit();
       }
    }
 
    // Assign output file to the output stream.
    StreamWriter myOutputWriter;
    myOutputWriter = File.AppendText(myFileName);
 
    /* Create a new text writer using the output stream and 
     * add it to the trace listeners. */
    TextWriterTraceListener myTextListener = new 
       TextWriterTraceListener(myOutputWriter);
    Trace.Listeners.Add(myTextListener);
 
    // Write output to the file.
    Trace.WriteLine("Test output");
 
    // Flush and close the output stream.
    myOutputWriter.Flush();
    myOutputWriter.Close();
 }
 

    
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Overloaded Method: Dispose()
Inherited
See base class member description: System.Diagnostics.TraceListener.Dispose

Summary
Releases all resources used by the TraceListener.
C# Syntax:
public void Dispose();
Implements:
IDisposable.Dispose
Remarks
Calling TraceListener.Dispose allows the resources used by the TraceListener. to be reallocated for other purposes. For more information about TraceListener.Dispose, see the conceptual topic at MSDN: cleaningupunmanagedresources.
See also:
MSDN: cleaningupunmanagedresources

Return to top


Overloaded Method: Dispose(
   bool disposing
)
Summary
Disposes this TextWriterTraceListener object.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected override void Dispose(
   bool disposing
);
Parameters:

disposing

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Fail(
   string message
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Fail

Summary
Emits an error message to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Fail(
   string message
);
Parameters:

message

A message to emit.

Remarks
The default behavior is to display the specified message in a message box when the application is running in a user-interface mode, and to the TraceListener instances in a TraceListenerCollection collection. By default, the TraceListenerCollection collection has an instance of a DefaultTraceListener. You can customize this behavior by adding a TraceListener to or removing one from the collection.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Fail(
   string message,
   string detailMessage
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Fail

Summary
Emits an error message, and a detailed error message to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Fail(
   string message,
   string detailMessage
);
Parameters:

message

A message to emit.

detailMessage

A detailed message to emit.

Remarks
The default behavior is to display the message and detailed message in a message box when the application is running in a user-interface mode, and to the TraceListener instances in a TraceListenerCollection collection. By default, the TraceListenerCollection collection has an instance of a DefaultTraceListener. You can customize this behavior by adding a TraceListener to or removing one from the collection.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~TextWriterTraceListener();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: Flush()
Summary
Flushes the output buffer for the TextWriterTraceListener.Writer.
C# Syntax:
public override void Flush();
Example
The following example implements a TextWriterTraceListener named myTextListener , which uses a StreamWriter called myOutputWriter to write to a file named TestFile.txt . The example creates the file, stream, and text writer, writes one line of text to the file, and then flushes and closes the stream.
public static void Main(string[] args) {
    // Create a file for output named TestFile.txt.
    String myFileName = "TestFile.txt";
    if(!File.Exists(myFileName)) {
       Stream myFile = File.Create(myFileName);
       // If the file cannot be created, exit the application.
       if(myFile == null) {
          Console.WriteLine("Could not create file");
          Application.Exit();
       }
    }
 
    // Assign output file to the output stream.
    StreamWriter myOutputWriter;
    myOutputWriter = File.AppendText(myFileName);
 
    /* Create a new text writer using the output stream and 
     * add it to the trace listeners. */
    TextWriterTraceListener myTextListener = new 
       TextWriterTraceListener(myOutputWriter);
    Trace.Listeners.Add(myTextListener);
 
    // Write output to the file.
    Trace.WriteLine("Test output");
 
    // Flush and close the output stream.
    myOutputWriter.Flush();
    myOutputWriter.Close();
 }
 

    
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Write(
   object o
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Write

Summary
Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Write(
   object o
);
Parameters:

o

An Object whose fully qualified class name you want to write.

See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Write(
   string message
)
Summary
Writes a message to this instance's TextWriterTraceListener.Writer.
C# Syntax:
public override void Write(
   string message
);
Parameters:

message

A message to write.

Example
The following example implements a TextWriterTraceListener named myWriter to write to the console screen. The example writes two lines to the console screen. Note the second write appears on the same line as the first write. The example then flushes and closes the stream.
public static void Main(string[] args) {
    /* Create a text writer that writes to the console screen and add
     * it to the trace listeners */
    TextWriterTraceListener myWriter = new TextWriterTraceListener();
    myWriter.Writer = System.Console.Out;
    Trace.Listeners.Add(myWriter);
 
    // Write the output to the console screen.
    myWriter.Write("Write to console screen. ");
    myWriter.WriteLine("Again, write to the Console screen.");
 
    // Flush and close the output.
    myWriter.Flush();
    myWriter.Close();
 }


    
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded Method: Write(
   object o,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Write

Summary
Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Write(
   object o,
   string category
);
Parameters:

o

An Object whose fully qualified class name you want to write.

category

A category name used to organize the output.

See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Write(
   string message,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Write

Summary
Writes a category name and a message to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Write(
   string message,
   string category
);
Parameters:

message

A message to write.

category

A category name used to organize the output.

See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: WriteIndent()
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteIndent

Summary
Writes the indent to the listener you create when you implement this class, and resets the TraceListener.NeedIndent property to false.
C# Syntax:
protected virtual void WriteIndent();
Remarks
Writes the indent and resets TraceListener.NeedIndent to false. Call this method if TraceListener.NeedIndent is true, when you are overloading TraceListener.Write and TraceListener.WriteLine. By default, this method uses blank spaces for indentation.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   object o
)
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteLine

Summary
Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
C# Syntax:
public virtual void WriteLine(
   object o
);
Parameters:

o

An Object whose fully qualified class name you want to write.

Remarks
The typical line terminator you might implement is a carriage return followed by a line feed (\r\n).
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   string message
)
Summary
Writes a message to this instance's TextWriterTraceListener.Writer followed by a line terminator. The default line terminator is a carriage return followed by a line feed (\r\n).
C# Syntax:
public override void WriteLine(
   string message
);
Parameters:

message

A message to write.

Example
The following example implements a TextWriterTraceListener named myWriter to write to the console screen. The example writes two lines to the console screen. Note the second write appears on the same line as the first write. The example then flushes and closes the stream.
public static void Main(string[] args) {
    /* Create a text writer that writes to the console screen and add
     * it to the trace listeners */
    TextWriterTraceListener myWriter = new TextWriterTraceListener();
    myWriter.Writer = System.Console.Out;
    Trace.Listeners.Add(myWriter);
 
    // Write the output to the console screen.
    myWriter.Write("Write to the Console screen. ");
    myWriter.WriteLine("Again, write to console screen.");
 
    // Flush and close the output.
    myWriter.Flush();
    myWriter.Close();
 }


    
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Stream | TextWriter | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   object o,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteLine

Summary
Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
C# Syntax:
public virtual void WriteLine(
   object o,
   string category
);
Parameters:

o

An Object whose fully qualified class name you want to write.

category

A category name used to organize the output.

Remarks
The typical line terminator you might implement is a carriage return followed by a line feed (\r\n).
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   string message,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteLine

Summary
Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.
C# Syntax:
public virtual void WriteLine(
   string message,
   string category
);
Parameters:

message

A message to write.

category

A category name used to organize the output.

Remarks
The typical line terminator you might implement is a carriage return followed by a line feed (\r\n).
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.