Trace.Listeners Trace.Listeners Trace.Listeners Trace.Listeners Property

定義

取得監視追蹤輸出的接聽項 (Listener) 的集合。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; }
member this.Listeners : System.Diagnostics.TraceListenerCollection
Public Shared ReadOnly Property Listeners As TraceListenerCollection

屬性值

TraceListenerCollection,表示監視追蹤輸出的 TraceListener 型別的集合。A 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. 然後, 此程式碼會將新的Listeners接聽程式新增至。The 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. 根據預設, 集合會包含DefaultTraceListener類別的實例。By default, the collection contains an instance of the DefaultTraceListener class. 如果您想要移除預設接聽程式, 請呼叫Remove方法, 並將的實例DefaultTraceListener傳遞給它。If you want to remove the default listener, call the Remove method, and pass it the instance of the DefaultTraceListener. 若要將輸出重新導向至主控台視窗, 請新增ConsoleTraceListener類別的實例。To redirect output to the console window, add an instance of the ConsoleTraceListener class.

注意

集合是由DebugTrace類別共用; 將追蹤接聽項新增至其中一個類別, 會將接聽程式新增至兩者。 ListenersThe Listeners collection is shared by both the Debug and the Trace classes; adding a trace listener to either class adds the listener to both.

安全性

SecurityPermission
用於操作非受控碼。for operating with unmanaged code. 安全性動作: DemandSecurity action: Demand. 相關聯的列舉:UnmanagedCodeAssociated enumeration: UnmanagedCode

適用於

另請參閱