Trace.Listeners 属性

定义

获取正在监视跟踪输出的侦听器集合。Gets the collection of listeners that is monitoring the trace output.

public:
 static property System::Diagnostics::TraceListenerCollection ^ Listeners { System::Diagnostics::TraceListenerCollection ^ get(); };
public static System.Diagnostics.TraceListenerCollection? Listeners { get; }
public static System.Diagnostics.TraceListenerCollection Listeners { get; }
member this.Listeners : System.Diagnostics.TraceListenerCollection
Public Shared ReadOnly Property Listeners As TraceListenerCollection

属性值

TraceListenerCollection

表示监视跟踪输出的类型 TraceListener 集合的 TraceListenerCollectionA TraceListenerCollection that represents a collection of type TraceListener monitoring the trace output.

示例

下面的示例创建一个 ConsoleTraceListener 输出到控制台屏幕的。The following example creates a ConsoleTraceListener that outputs to the console screen. 然后,该代码将新侦听器添加到 ListenersThe code then adds the new listener to the Listeners.

// Create a ConsoletTraceListener and add it to the trace listeners.
#if defined(TRACE)
ConsoleTraceListener^ myWriter = gcnew ConsoleTraceListener( );
Trace::Listeners->Add( myWriter );
#endif
/* 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. 
Dim myWriter As New ConsoleTraceListener()
Trace.Listeners.Add(myWriter)

注解

侦听器从跟踪输出生成格式输出。The listeners produce formatted output from the trace output. 默认情况下,集合包含类的实例 DefaultTraceListenerBy default, the collection contains an instance of the DefaultTraceListener class. 如果要删除默认侦听器,请调用 Remove 方法,并向其传递的实例 DefaultTraceListenerIf you want to remove the default listener, call the Remove method, and pass it the instance of the DefaultTraceListener. 若要将输出重定向到控制台窗口,请添加类的实例 ConsoleTraceListenerTo redirect output to the console window, add an instance of the ConsoleTraceListener class.

备注

Listeners集合由 DebugTrace 类共享; 将跟踪侦听器添加到任一类会将侦听器添加到这两个类中。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.

适用于

另请参阅