Trace.Close Yöntem

Tanım

Çıkış arabelleği temizler ve ardından öğesini Listenerskapatır.

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 ()
Öznitelikler

Örnekler

Aşağıdaki örnek adlı TextWriterTraceListenerbir myTextListener oluşturur. myTextListeneradlı StreamWriterbir myOutputWriter dosyaya yazmak için adlı TestFile.txt bir kullanır. Örnek dosyayı oluşturur, akış ve metin yazar, dosyaya bir satır metin yazar ve ardından çıkışı boşaltır ve kapatır.

// 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

Açıklamalar

Çıktı, gibi TextWriterTraceListenerbir dosyaya gidiyorsa bu yöntemi kullanın.

Akışın boşaltılması, veya Flushöğesini açıkça çağırmadığınız Close sürece temel alınan kodlayıcısını temizlemez. ayarı AutoFlush , true verilerin arabellekten akışa boşaltılacağı, ancak kodlayıcı durumunun boşaltılmayacağı anlamına gelir. Bu, kodlayıcının durumunu (kısmi karakterler) koruyarak sonraki karakter bloğunu doğru şekilde kodlamasını sağlar. Bu senaryo UTF8 ve UTF7'yi etkiler; burada belirli karakterler yalnızca kodlayıcı bitişik karakter veya karakterleri aldıktan sonra kodlanabilir.

Şunlara uygulanır

Ayrıca bkz.