This documentation is archived and is not being maintained.

TextWriterTraceListener.WriteLine Method

Writes a message to this instance's Writer followed by a line terminator.

Overload List

Writes a message to this instance's Writer followed by a line terminator. The default line terminator is a carriage return followed by a line feed (\r\n).

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

Inherited from TraceListener.

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

Inherited from TraceListener.

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

Inherited from TraceListener.

[Visual Basic] Overloads Public Overridable Sub WriteLine(String, String)
[C#] public virtual void WriteLine(string, string);
[C++] public: virtual void WriteLine(String*, String*);
[JScript] public function WriteLine(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 WriteLine. 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 the Console screen. ")
        myWriter.WriteLine("Again, write to console screen.")
        
        ' Flush and close the output.
        myWriter.Flush()
        myWriter.Close()
    End Sub

End Class

[C#] 
public class Sample
{

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

}

[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 the Console screen. ");
    myWriter->WriteLine(S"Again, write to 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: