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.

  NameDescription
Public propertySupported by the XNA FrameworkCountGets the number of listeners in the list.
Public propertySupported by the XNA FrameworkItem[Int32]Gets or sets the TraceListener at the specified index.
Public propertySupported by the XNA FrameworkItem[String]Gets the first TraceListener in the list with the specified name.
Top

  NameDescription
Public methodSupported by the XNA FrameworkAddAdds a TraceListener to the list.
Public methodAddRange(TraceListener[])Adds an array of TraceListener objects to the list.
Public methodAddRange(TraceListenerCollection)Adds the contents of another TraceListenerCollection to the list.
Public methodSupported by the XNA FrameworkClearClears all the listeners from the list.
Public methodSupported by the XNA FrameworkContainsChecks whether the list contains the specified listener.
Public methodSupported by the XNA FrameworkCopyToCopies a section of the current TraceListenerCollection list to the specified array at the specified index.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetEnumeratorGets an enumerator for this list.
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkIndexOfGets the index of the specified listener.
Public methodSupported by the XNA FrameworkInsertInserts the listener at the specified index.
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkRemove(String)Removes from the collection the first TraceListener with the specified name.
Public methodSupported by the XNA FrameworkRemove(TraceListener)Removes from the collection the specified TraceListener.
Public methodSupported by the XNA FrameworkRemoveAtRemoves from the collection the TraceListener at the specified index.
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodSupported by the XNA FrameworkCast<TResult>()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkCast<TResult>()Overloaded. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkOfType<TResult>()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkOfType<TResult>()Overloaded. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkICollection.CopyToInfrastructure. Copies a section of the current TraceListenerCollection to the specified array of TraceListener objects.
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkICollection.IsSynchronizedInfrastructure. Gets a value indicating whether access to the TraceListenerCollection is synchronized (thread safe).
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkICollection.SyncRootInfrastructure. Gets an object that can be used to synchronize access to the TraceListenerCollection.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkIList.AddInfrastructure. Adds a trace listener to the TraceListenerCollection.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkIList.ContainsInfrastructure. Determines whether the TraceListenerCollection contains a specific object.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkIList.IndexOfInfrastructure. Determines the index of a specific object in the TraceListenerCollection.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkIList.InsertInfrastructure. Inserts a TraceListener object at the specified position in the TraceListenerCollection.
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkIList.IsFixedSizeInfrastructure. Gets a value indicating whether the TraceListenerCollection has a fixed size.
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkIList.IsReadOnlyInfrastructure. Gets a value indicating whether the TraceListenerCollection is read-only
Explicit interface implemetationPrivate propertySupported by the XNA FrameworkIList.ItemInfrastructure. Gets or sets the TraceListener at the specified index in the TraceListenerCollection.
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkIList.RemoveInfrastructure. 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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft