Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método Trace.Close ()

 

Publicado: noviembre de 2016

Vacía el búfer de salida y, a continuación, cierra los Listeners.

Espacio de nombres:   System.Diagnostics
Ensamblado:  System (en System.dll)

<ConditionalAttribute("TRACE")>
Public Shared Sub Close

Use this method when the output is going to a file, such as to the T:System.Diagnostics.TextWriterTraceListener.

Flushing the stream will not flush its underlying encoder unless you explicitly call M:System.Diagnostics.Trace.Flush or M:System.Diagnostics.Trace.Close. Setting P:System.Diagnostics.Trace.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.

The following example creates a T:System.Diagnostics.TextWriterTraceListener named myTextListener. myTextListener uses a T:System.IO.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 /d:TRACE=True when compiling.

Imports System
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 'Main

End Class

SecurityPermission

for operating with unmanaged code. Security action: F:System.Security.Permissions.SecurityAction.Demand. Associated enumeration: F:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode

.NET Framework
Disponible desde 1.1
Volver al principio
Mostrar: