Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Listeners Property

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

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 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")


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft