TextWriterTraceListener.Flush 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
刷新 Writer 的输出缓冲区。
public:
override void Flush();
public override void Flush ();
override this.Flush : unit -> unit
Public Overrides Sub Flush ()
示例
以下示例实现一个名为 TextWriterTraceListenermyTextListener
的 ,它使用 StreamWriter 调用 myOutputWriter
的 写入名为 的文件 TestFile.txt
。 该示例创建文件、流和文本编写器,将一行文本写入文件,然后刷新并关闭流。
#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
}
#define TRACE
using System;
using System.IO;
using System.Diagnostics;
public class TextWriterTraceListenerSample
{
public static void Main()
{
TextWriterTraceListener myTextListener = null;
// Create a file for output named TestFile.txt.
string myFileName = "TestFile.txt";
StreamWriter myOutputWriter = new StreamWriter(myFileName, true);
// Add a TextWriterTraceListener for the file.
myTextListener = new TextWriterTraceListener(myOutputWriter);
Trace.Listeners.Add(myTextListener);
// Write trace output to all trace listeners.
Trace.WriteLine(DateTime.Now.ToString() + " - Trace output");
// Remove and close the file writer/trace listener.
myTextListener.Flush();
Trace.Listeners.Remove(myTextListener);
myTextListener.Close();
}
}
#Const TRACE=True
Imports System.IO
Imports System.Diagnostics
Public Class TextWriterTraceListenerSample
Public Shared Sub Main()
Dim myTextListener As TextWriterTraceListener = Nothing
' Create a file for output named TestFile.txt.
Dim myFileName As String = "TestFile.txt"
Dim myOutputWriter As New StreamWriter(myFileName, True)
' Add a TextWriterTraceListener for the file.
myTextListener = New TextWriterTraceListener(myOutputWriter)
Trace.Listeners.Add(myTextListener)
' Write trace output to all trace listeners.
Trace.WriteLine(DateTime.Now.ToString() + " - Trace output")
' Remove and close the file writer/trace listener.
myTextListener.Flush()
Trace.Listeners.Remove(myTextListener)
myTextListener.Close()
End Sub
End Class