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)

适用于

另请参阅