TextWriterTraceListener::Flush Method ()
.NET Framework (current version)
Flushes the output buffer for the Writer.
Assembly: System (in System.dll)
The following example implements a TextWriterTraceListener named myTextListener, which uses a StreamWriter called myOutputWriter to write to a file named TestFile.txt. The example creates the file, stream, and text writer, writes one line of text to the file, and then flushes and closes the stream.
#using <System.dll> using namespace System; using namespace System::IO; using namespace System::Diagnostics; void main() { #if defined(TRACE) TextWriterTraceListener^ myTextListener = nullptr; // Create a file for output named TestFile.txt. String^ myFileName = "TestFile.txt"; StreamWriter^ myOutputWriter = gcnew StreamWriter( myFileName,true ); // Add a TextWriterTraceListener for the file. if ( myOutputWriter ) { myTextListener = gcnew TextWriterTraceListener( myOutputWriter ); Trace::Listeners->Add( myTextListener ); } // Write trace output to all trace listeners. Trace::WriteLine( String::Concat( DateTime::Now.ToString(), " - Trace output" ) ); if ( myTextListener ) { // Remove and close the file writer/trace listener. myTextListener->Flush(); Trace::Listeners->Remove( myTextListener ); myTextListener->Close(); } #endif }
.NET Framework
Available since 1.1
Available since 1.1
Show: