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.

Trace.Listeners Property

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

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public static TraceListenerCollection Listeners { get; }
/** @property */
public static TraceListenerCollection get_Listeners ()

public static function get Listeners () : TraceListenerCollection

Not applicable.

Property Value

A TraceListenerCollection that represents a collection of type TraceListener monitoring the trace output.

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 ConsoleTraceListener class.

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

/* Create a ConsoleTraceListener and add it to the trace listeners. */
ConsoleTraceListener myWriter = new
   ConsoleTraceListener();
Trace.Listeners.Add(myWriter);


/* Create a ConsoleTraceListener and add it to the trace listeners. 
 */
ConsoleTraceListener myWriter =
    new ConsoleTraceListener();
Trace.get_Listeners().Add(myWriter);

// Create a ConsoletTraceListener and add it to the trace listeners.
@if(@TRACE)
var myWriter : ConsoleTraceListener = new ConsoleTraceListener()
Trace.Listeners.Add(myWriter)
@end

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft