This topic has not yet been rated - Rate this topic

TraceListenerCollection Class

Provides a thread-safe list of TraceListener objects.

System.Object
  System.Diagnostics.TraceListenerCollection

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)
public class TraceListenerCollection : IList, 
	ICollection, IEnumerable

The TraceListenerCollection type exposes the following members.

  Name Description
Public property Supported by the XNA Framework Count Gets the number of listeners in the list.
Public property Supported by the XNA Framework Item[Int32] Gets or sets the TraceListener at the specified index.
Public property Supported by the XNA Framework Item[String] Gets the first TraceListener in the list with the specified name.
Top
  Name Description
Public method Supported by the XNA Framework Add Adds a TraceListener to the list.
Public method AddRange(TraceListener[]) Adds an array of TraceListener objects to the list.
Public method AddRange(TraceListenerCollection) Adds the contents of another TraceListenerCollection to the list.
Public method Supported by the XNA Framework Clear Clears all the listeners from the list.
Public method Supported by the XNA Framework Contains Checks whether the list contains the specified listener.
Public method Supported by the XNA Framework CopyTo Copies a section of the current TraceListenerCollection list to the specified array at the specified index.
Public method Supported by the XNA Framework Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by the XNA Framework Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework GetEnumerator Gets an enumerator for this list.
Public method Supported by the XNA Framework GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by the XNA Framework GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Supported by the XNA Framework IndexOf Gets the index of the specified listener.
Public method Supported by the XNA Framework Insert Inserts the listener at the specified index.
Protected method Supported by the XNA Framework MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework Remove(String) Removes from the collection the first TraceListener with the specified name.
Public method Supported by the XNA Framework Remove(TraceListener) Removes from the collection the specified TraceListener.
Public method Supported by the XNA Framework RemoveAt Removes from the collection the TraceListener at the specified index.
Public method Supported by the XNA Framework ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public Extension Method AsParallel Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension Method AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method Supported by the XNA Framework Cast<TResult> Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method Supported by the XNA Framework OfType<TResult> Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  Name Description
Explicit interface implemetation Private method Supported by the XNA Framework ICollection.CopyTo Infrastructure. Copies a section of the current TraceListenerCollection to the specified array of TraceListener objects.
Explicit interface implemetation Private property Supported by the XNA Framework ICollection.IsSynchronized Infrastructure. Gets a value indicating whether access to the TraceListenerCollection is synchronized (thread safe).
Explicit interface implemetation Private property Supported by the XNA Framework ICollection.SyncRoot Infrastructure. Gets an object that can be used to synchronize access to the TraceListenerCollection.
Explicit interface implemetation Private method Supported by the XNA Framework IList.Add Infrastructure. Adds a trace listener to the TraceListenerCollection.
Explicit interface implemetation Private method Supported by the XNA Framework IList.Contains Infrastructure. Determines whether the TraceListenerCollection contains a specific object.
Explicit interface implemetation Private method Supported by the XNA Framework IList.IndexOf Infrastructure. Determines the index of a specific object in the TraceListenerCollection.
Explicit interface implemetation Private method Supported by the XNA Framework IList.Insert Infrastructure. Inserts a TraceListener object at the specified position in the TraceListenerCollection.
Explicit interface implemetation Private property Supported by the XNA Framework IList.IsFixedSize Infrastructure. Gets a value indicating whether the TraceListenerCollection has a fixed size.
Explicit interface implemetation Private property Supported by the XNA Framework IList.IsReadOnly Infrastructure. Gets a value indicating whether the TraceListenerCollection is read-only
Explicit interface implemetation Private property Supported by the XNA Framework IList.Item Infrastructure. Gets or sets the TraceListener at the specified index in the TraceListenerCollection.
Explicit interface implemetation Private method Supported by the XNA Framework IList.Remove Infrastructure. Removes an object from the TraceListenerCollection.
Top

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.

The following example creates a TextWriterTraceListener that writes to the console screen. The code then adds the new listener to the Trace.Listeners.


        /* Create a ConsoleTraceListener and add it to the trace listeners. */
        ConsoleTraceListener myWriter = new
           ConsoleTraceListener();
        Trace.Listeners.Add(myWriter);



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ