共用方式為


TraceListenerCollection.Add(TraceListener) 方法

定義

TraceListener 加入清單中。

public:
 int Add(System::Diagnostics::TraceListener ^ listener);
public int Add (System.Diagnostics.TraceListener listener);
member this.Add : System.Diagnostics.TraceListener -> int
Public Function Add (listener As TraceListener) As Integer

參數

listener
TraceListener

要加入至清單的 TraceListener

傳回

要插入新接聽程式的位置。

範例

下列範例會 TextWriterTraceListener 建立輸出至主控台畫面的 。 程式代碼接著會將新的接聽程式新增至 Trace.Listeners

/* Create a listener, which outputs to the console screen, and 
 * add it to the trace listeners. */
TextWriterTraceListener^ myWriter = gcnew TextWriterTraceListener;
myWriter->Writer = System::Console::Out;
Trace::Listeners->Add( myWriter );
/* Create a listener, which outputs to the console screen, and
  * add it to the trace listeners. */
TextWriterTraceListener myWriter = new TextWriterTraceListener();
myWriter.Writer = System.Console.Out;
Trace.Listeners.Add(myWriter);
' Create a listener, which outputs to the console screen, and
' add it to the trace listeners. 
Dim myWriter As New TextWriterTraceListener()
myWriter.Writer = System.Console.Out
Trace.Listeners.Add(myWriter)

適用於

另請參閱