Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

TextWriterTraceListener.Write Method

Writes a message to this instance's Writer.

Overload List

Writes a message to this instance's Writer.

[Visual Basic] Overloads Overrides Public Sub Write(String)
[C#] public override void Write(string);
[C++] public: void Write(String*);
[JScript] public override function Write(String);

Inherited from TraceListener.

[Visual Basic] Overloads Public Overridable Sub Write(Object)
[C#] public virtual void Write(object);
[C++] public: virtual void Write(Object*);
[JScript] public function Write(Object);

Inherited from TraceListener.

[Visual Basic] Overloads Public Overridable Sub Write(Object, String)
[C#] public virtual void Write(object, string);
[C++] public: virtual void Write(Object*, String*);
[JScript] public function Write(Object, String);

Inherited from TraceListener.

[Visual Basic] Overloads Public Overridable Sub Write(String, String)
[C#] public virtual void Write(string, string);
[C++] public: virtual void Write(String*, String*);
[JScript] public function Write(String, String);

Example

[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Write. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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
        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()
    End Sub

End Class

[C#] 
public class Sample 
{

 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();
 }

}

[C++] 
int main() {
    /* 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(S"Write to console screen. ");
    myWriter->WriteLine(S"Again, write to the Console screen.");
 
    // Flush and close the output.
    myWriter->Flush();
    myWriter->Close();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

TextWriterTraceListener Class | TextWriterTraceListener Members | System.Diagnostics Namespace

Show:
© 2015 Microsoft