Freigeben über


TextWriterTraceListener.Write(String) Methode

Definition

Schreibt eine Meldung in den Writer dieser Instanz.

public:
 override void Write(System::String ^ message);
public override void Write (string? message);
public override void Write (string message);
override this.Write : string -> unit
Public Overrides Sub Write (message As String)

Parameter

message
String

Eine zu schreibende Meldung.

Beispiele

Im folgenden Beispiel wird ein TextWriterTraceListener mit dem Namen myWriter implementiert, um in den Konsolenbildschirm zu schreiben. Im Beispiel werden zwei Zeilen in den Konsolenbildschirm geschrieben. Beachten Sie, dass der zweite Schreibvorgang in derselben Zeile wie der erste Schreibvorgang angezeigt wird. Anschließend wird der Stream geleert und geschlossen.

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 console screen. " );
   myWriter->WriteLine( "Again, write to the Console screen." );
   
   // Flush and close the output.
   myWriter->Flush();
   myWriter->Close();
   #endif
}
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();
 }
}
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

Gilt für:

Weitere Informationen