Debug.Close Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Flushes the output buffer and then calls the Close
method on each of the 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 ()
- Attributes
The following example creates a TextWriterTraceListener named myTextListener
. myTextListener
uses a StreamWriter called myOutputWriter
to write to a file named TestFile.txt
. The example creates the file, stream, and text writer, writes one line of text to the file, and then flushes and closes the output.
// 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
Use this method when the output goes to a file, such as to the TextWriterTraceListener.
Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or Close. Setting AutoFlush to true
means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.
Продукт | Версії |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Відгук про .NET
.NET – це проект із відкритим кодом. Виберіть посилання, щоб надати відгук: