ClassSystem.Diagnostics.Debug SyntaxDim result As TraceListenerCollection = Debug.Listeners DescriptionThe 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 GlanceWhile 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. ExampleThe 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 AlsoDebug Class |