Прочетете на английски Редактиране

Споделяне чрез


Trace.Listeners Property

Definition

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

C#
public static System.Diagnostics.TraceListenerCollection Listeners { get; }

Property Value

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

Examples

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

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

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

Бележка

The Listeners collection is shared by both the Debug and the Trace classes; adding a trace listener to either class adds the listener to both.

Applies to

Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also