Debug.Close メソッド

定義

出力バッファーをフラッシュしてから、各 ListenersClose を呼び出します。

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

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

// Specify /DDEBUG when compiling.

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

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

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

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

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

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

Imports System.IO
Imports System.Diagnostics

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

End Class

注釈

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

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

適用対象

こちらもご覧ください