VB.NET Language in a Nutshell

   
Debug.Listeners Property

Class

System.Diagnostics.Debug

Syntax

Debug.Listeners

Description

Retrieves the TraceListenerCollection collection of all TraceListener objects that monitor the debug output.

Example

The following code adds a text file to the listeners collection. As a result, all Debug.Write... methods will not only send the output to the Output window (the default listener) but also to the text file:

' Define a new TextWriterTraceListener Dim trace As New TextWriterTraceListener( ) ' Define a new FileStream object Dim fs As FileStream = New FileStream("c:\log.txt", FileMode.Append, _ FileAccess.Write) ' Set the Writer property to a new StreamWriter for this FileStream trace.Writer = New StreamWriter(fs) ' Add listener Debug.Listeners.Add(trace) ' Output Debug.WriteLine("xxxxx") Debug.WriteLine("yyyyy") ' Close up Debug.Close( ) fs.Close( ) ' Remove listener Debug.Listeners.Remove(trace) ' This goes only to Output window Debug.WriteLine("zzzzz")

   

Категории