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 ()
특성

예제

다음 예제에서는 라는 를 TextWriterTraceListenermyTextListener만듭니다. myTextListenerStreamWriter 라는 파일에 TestFile.txt쓰기 위해 호출 myOutputWriter 된 를 사용합니다. 이 예제에서는 파일, 스트림 및 텍스트 기록기를 만들고 한 줄의 텍스트를 파일에 쓴 다음 출력을 플러시하고 닫습니다.

// 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에 영향을 줍니다.

적용 대상

추가 정보