TextWriterTraceListener Constructor ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the TextWriterTraceListener class with TextWriter as the output recipient.

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

public:
TextWriterTraceListener()

This constructor uses the TextWriter stream as the recipient of the tracing or debugging output. Its Name property is initialized to an empty string ("", or String::Empty).

The following example creates a TextWriterTraceListener using the TextWriterTraceListener() constructor. It sets the Writer property to console output, and then adds the TextWriterTraceListener to the TraceListenerCollection. It writes a message in two segments, and then closes the TextWriterTraceListener.

void main()
{
   #if defined(TRACE)
   // Create a text writer that writes to the console screen and add
   // it to the trace listeners.
   TextWriterTraceListener^ myWriter = gcnew 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();
   #endif
}

.NET Framework
Available since 1.1
Return to top
Show: