Debug.Close Метод

Определение

Очищает выходной буфер, а затем вызывает метод Close на каждый Listeners.

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 именем myTextListener. myTextListenerStreamWriter использует для myOutputWriter записи в файл с именем TestFile.txt. В этом примере создается файл, поток и модуль записи текста, записывается одна строка текста в файл, а затем выполняется очистка и закрытие выходных данных.

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

Очистка потока не приведет к очистке его базового кодировщика, если вы явно не вызовете Flush или Close. Установка значения AutoFlushtrue означает, что данные будут сброшены из буфера в поток, но состояние кодировщика не будет сброшено. Это позволяет кодировщику сохранять свое состояние (частичные символы), чтобы он смог правильно кодировать следующий блок символов. Этот сценарий влияет на UTF8 и UTF7, где определенные символы могут быть закодированы только после того, как кодировщик получит смежные символы или символы.

Применяется к

См. также раздел