O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

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")

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required