TextWriterTraceListener Constructor ()


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 Sub New

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.

Public Class Sample

    Public Shared Sub Main()
        ' Create a text writer that writes to the console screen and add
        ' it to the trace listeners 
        Dim myWriter As New TextWriterTraceListener()
        myWriter.Writer = System.Console.Out

        ' 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.
    End Sub

End Class

.NET Framework
Available since 1.1
Return to top