Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Debug.Listeners Property

Gets the collection of listeners that is monitoring the debug output.

[Visual Basic]
Public Shared ReadOnly Property Listeners As _
   TraceListenerCollection
[C#]
public static TraceListenerCollection Listeners {get;}
[C++]
public: __property static TraceListenerCollection* get_Listeners();
[JScript]
public static function get Listeners() : TraceListenerCollection;

Property Value

A TraceListenerCollection representing a collection of type TraceListener that monitors the debug output.

Remarks

The listeners produce formatted output from the debug output. By default, the collection contains an instance of the DefaultTraceListener class. To remove the default listener, call the Remove method, and pass it the instance of the DefaultTraceListener. To redirect output to the console window, add an instance of the TextWriterTraceListener that uses the Console.Out stream.

Example

The following example creates a TextWriterTraceListener that outputs to the console screen. The code then adds the new listener to the Listeners.

[Visual Basic] 
' Create a listener that outputs to the console screen, and 
' add it to the debug listeners. 
Dim myWriter As New TextWriterTraceListener(System.Console.Out)
Debug.Listeners.Add(myWriter)

[C#] 
/* Create a listener that outputs to the console screen, and 
  * add it to the debug listeners. */
 TextWriterTraceListener myWriter = new 
    TextWriterTraceListener(System.Console.Out);
 Debug.Listeners.Add(myWriter);


[C++] 
/* Create a listener that outputs to the console screen, and 
  * add it to the debug listeners. */
 TextWriterTraceListener * myWriter = new 
     TextWriterTraceListener(System::Console::Out);
 Debug::Listeners->Add(myWriter);


[JScript] 
/* Create a listener, which outputs to the console screen, and 
  * add it to the debug listeners. */
 var myWriter : TextWriterTraceListener = new 
    TextWriterTraceListener(System.Console.Out);
 Debug.Listeners.Add(myWriter);

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Debug Class | Debug Members | System.Diagnostics Namespace | Debug | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft