Trace.Close メソッド

定義

出力バッファーをフラッシュし、Listeners を閉じます。

public:
 static void Close();
[System.Diagnostics.Conditional("TRACE")]
public static void Close ();
[<System.Diagnostics.Conditional("TRACE")>]
static member Close : unit -> unit
Public Shared Sub Close ()
属性

次の例では、 という名前の を TextWriterTraceListener 作成します myTextListenermyTextListener という名前の StreamWriter ファイルに書き込むには、 という myOutputWriter 名前 TestFile.txtの を使用します。 この例では、ファイル、ストリーム、テキスト ライターを作成し、1 行のテキストをファイルに書き込み、出力をフラッシュして閉じます。

// Specify /DTRACE when compiling.

#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;

void main()
{
     #if defined(TRACE)
    // Create a file for output named TestFile.txt.
    FileStream^ myFileStream = 
        gcnew FileStream( "TestFile.txt", FileMode::Append );
   
    // Create a new text writer using the output stream 
    // and add it to the trace listeners.
    TextWriterTraceListener^ myTextListener = 
        gcnew TextWriterTraceListener( myFileStream );
    Trace::Listeners->Add( myTextListener );
   
    // Write output to the file.
    Trace::WriteLine( "Test output" );
   
    // Flush and close the output stream.
    Trace::Flush();
    Trace::Close();
    #endif
}
// Specify /d:TRACE when compiling.

using System;
using System.IO;
using System.Diagnostics;

class Test
{
    static void Main()
    {
        // Create a file for output named TestFile.txt.
        using (FileStream myFileStream =
            new FileStream("TestFile.txt", FileMode.Append))
        {
            // Create a new text writer using the output stream
            // and add it to the trace listeners.
            TextWriterTraceListener myTextListener =
                new TextWriterTraceListener(myFileStream);
            Trace.Listeners.Add(myTextListener);

            // Write output to the file.
            Trace.WriteLine("Test output");

            // Flush and close the output stream.
            Trace.Flush();
            Trace.Close();
        }
    }
}
' Specify /d:TRACE=True when compiling.

Imports System.IO
Imports System.Diagnostics

Class Test
    
    Shared Sub Main()
    
        ' Create a file for output named TestFile.txt.
        Using myFileStream As New FileStream("TestFile.txt", FileMode.Append)
        
            ' Create a new text writer using the output stream
            ' and add it to the trace listeners. 
            Dim myTextListener As New TextWriterTraceListener(myFileStream)
            Trace.Listeners.Add(myTextListener)
            
            ' Write output to the file.
            Trace.WriteLine("Test output")
            
            ' Flush and close the output stream.
            Trace.Flush()
            Trace.Close()
        
        End Using
        
    End Sub

End Class

注釈

出力が などのファイルに送信される場合は、このメソッドを使用します TextWriterTraceListener

または Closeを明示的に呼び出Flushさない限り、ストリームをフラッシュしても、基になるエンコーダーはフラッシュされません。 にtrue設定AutoFlushすると、データはバッファーからストリームにフラッシュされますが、エンコーダーの状態はフラッシュされません。 これにより、エンコーダーは状態 (部分的な文字) を保持して、次の文字ブロックを正しくエンコードできるようになります。 このシナリオは UTF8 と UTF7 に影響を与え、エンコーダーが隣接する文字を受信した後にのみ特定の文字をエンコードできます。

適用対象

こちらもご覧ください