Export (0) Print
Expand All

TraceListenerCollection.Add Method

Adds a TraceListener to the list.

[Visual Basic]
Public Function Add( _
   ByVal listener As TraceListener _
) As Integer
[C#]
public int Add(
 TraceListener listener
);
[C++]
public: int Add(
 TraceListener* listener
);
[JScript]
public function Add(
   listener : TraceListener
) : int;

Parameters

listener
A TraceListener to add to the list.

Return Value

The position at which the new listener was inserted.

Example

[Visual Basic, C#, C++] The following example creates a TextWriterTraceListener that outputs to the console screen. The code then adds the new listener to the Trace.Listeners.

[Visual Basic] 
' 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)


[C#] 
/* 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);
 

[C++] 
/* 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);
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

TraceListenerCollection Class | TraceListenerCollection Members | System.Diagnostics Namespace | TraceListenerCollection | TraceListener | DefaultTraceListener | TextWriterTraceListener | Debug | Trace

Show:
© 2015 Microsoft