Debug.Listeners Property


Debug.Listeners Property

Class

System.Diagnostics.Debug

Syntax

     Dim result As TraceListenerCollection = Debug.Listeners 

Description

The Listeners property retrieves a collection of all TraceListener objects that monitor the debug output. Each listener is a destination for all trace and debug information created by the application.

Usage at a Glance

While all Debug class features work within the development environment, they are disabled by default in code compiled for release. They must be specifically enabled if you wish to use them in a compiled application.

Example

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

     ' ----- Uses "Imports System.IO" above.     ' ----- Define a new listener object.     Dim fileTrace As New TextWriterTraceListener(  )     ' ----- Since the listener is generic and doesn't have any     '       specific destination, the code needs to create the     '       destination and associate it with the listener. In     '       this case, the destination will be a file stream.     Dim debugStream As FileStream = New FileStream("c:\log.txt", _        FileMode.Append, FileAccess.Write)     fileTrace.Writer = New StreamWriter(debugStream)     ' ----- Now the listener is ready to be used.     Debug.Listeners.Add(fileTrace)     ' ----- These Debug statements will go to the new file, and     '       also to the Output Window.     Debug.WriteLine("We are busy debug statements;")     Debug.WriteLine("we go to two places at once.")     ' ----- Test complete. Close all opened resources.     Debug.Listeners.Remove(fileTrace)     fileTrace.Close(  )     debugStream.Close(  )     ' ----- This Debug statement goes only to the Output Window.     Debug.WriteLine("I'm not really that busy.") 

See Also

Debug Class




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net