Export (0) Print
Expand All

Trace.Listeners Property

Gets the collection of listeners that is monitoring the trace 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 that represents a collection of type TraceListener monitoring the trace output.

Remarks

The listeners produce formatted output from the trace output. By default, the collection contains an instance of the DefaultTraceListener class. If you want 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, which outputs to the console screen, and 
' add it to the trace listeners. 
Dim myWriter As New TextWriterTraceListener(System.Console.Out)
Trace.Listeners.Add(myWriter)


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


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


[JScript] 
// Create a listener, which outputs to the console screen, and 
// add it to the trace listeners. 
var myWriter : TextWriterTraceListener = new TextWriterTraceListener(System.Console.Out)
Trace.Listeners.Add(myWriter)
Trace.Write("Error output")

Requirements

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

See Also

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

Show:
© 2014 Microsoft