Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TraceListenerCollection Class

Provides a thread-safe list of TraceListener objects.

For a list of all members of this type, see TraceListenerCollection Members.

System.Object
   System.Diagnostics.TraceListenerCollection

[Visual Basic]
Public Class TraceListenerCollection
   Implements IList, ICollection, IEnumerable
[C#]
public class TraceListenerCollection : IList, ICollection,
   IEnumerable
[C++]
public __gc class TraceListenerCollection : public IList,
   ICollection, IEnumerable
[JScript]
public class TraceListenerCollection implements IList, ICollection,
   IEnumerable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The TraceListenerCollection list is used to specify the output listeners for the Trace.Listeners and the Debug.Listeners collections. You cannot create an instance of this class.

This list is thread-safe, however the methods used to access the list and the enumerator do not take synchronization locks. Instead, the collection is copied, the copy is modified, and a reference is set to the copy of the collection. Methods like Add, Remove, and Clear modify the elements in the collection.

The TraceListenerCollection class provides the Count property for information about the list. It also provides the following methods: Contains, GetEnumerator, IndexOf.

This class also provides the following methods to modify the list: Add, Clear, Insert, and Remove. The CopyTo method copies a part of the list to an array. The RemoveAt method deletes the list member at a specified index number.

Example

The following example creates a TextWriterTraceListener that writes 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(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(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(System::Console::Out);
 Trace::Listeners->Add(myWriter);


[JScript] 
// Create a listener, which outputs to the console screen, and 
// add it to the trace listeners. 
var myWriter : TextWriterTraceListener = new TextWriterTraceListener(System.Console.Out)
Trace.Listeners.Add(myWriter)
Trace.Write("Error output")

Requirements

Namespace: System.Diagnostics

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

Assembly: System (in System.dll)

See Also

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.