TraceListenerCollection TraceListenerCollection TraceListenerCollection TraceListenerCollection Class

Definition

Provides a thread-safe list of TraceListener objects.

public ref class TraceListenerCollection : System::Collections::IList
public class TraceListenerCollection : System.Collections.IList
type TraceListenerCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class TraceListenerCollection
Implements IList
Inheritance
TraceListenerCollectionTraceListenerCollectionTraceListenerCollectionTraceListenerCollection
Implements

Examples

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

// Create a ConsoletTraceListener and add it to the trace listeners.
#if defined(TRACE)
ConsoleTraceListener^ myWriter = gcnew ConsoleTraceListener( );
Trace::Listeners->Add( myWriter );
#endif
/* Create a ConsoleTraceListener and add it to the trace listeners. */
ConsoleTraceListener myWriter = new
   ConsoleTraceListener();
Trace.Listeners.Add(myWriter);

' Create a ConsoleTraceListener and add it to the trace listeners. 
Dim myWriter As New ConsoleTraceListener()
Trace.Listeners.Add(myWriter)

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.

Properties

Count Count Count Count

Gets the number of listeners in the list.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets or sets the TraceListener at the specified index.

Item[String] Item[String] Item[String] Item[String]

Gets the first TraceListener in the list with the specified name.

Methods

Add(TraceListener) Add(TraceListener) Add(TraceListener) Add(TraceListener)

Adds a TraceListener to the list.

AddRange(TraceListenerCollection) AddRange(TraceListenerCollection) AddRange(TraceListenerCollection) AddRange(TraceListenerCollection)

Adds the contents of another TraceListenerCollection to the list.

AddRange(TraceListener[]) AddRange(TraceListener[]) AddRange(TraceListener[]) AddRange(TraceListener[])

Adds an array of TraceListener objects to the list.

Clear() Clear() Clear() Clear()

Clears all the listeners from the list.

Contains(TraceListener) Contains(TraceListener) Contains(TraceListener) Contains(TraceListener)

Checks whether the list contains the specified listener.

CopyTo(TraceListener[], Int32) CopyTo(TraceListener[], Int32) CopyTo(TraceListener[], Int32) CopyTo(TraceListener[], Int32)

Copies a section of the current TraceListenerCollection list to the specified array at the specified index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Gets an enumerator for this list.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(TraceListener) IndexOf(TraceListener) IndexOf(TraceListener) IndexOf(TraceListener)

Gets the index of the specified listener.

Insert(Int32, TraceListener) Insert(Int32, TraceListener) Insert(Int32, TraceListener) Insert(Int32, TraceListener)

Inserts the listener at the specified index.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(String) Remove(String) Remove(String) Remove(String)

Removes from the collection the first TraceListener with the specified name.

Remove(TraceListener) Remove(TraceListener) Remove(TraceListener) Remove(TraceListener)

Removes from the collection the specified TraceListener.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes from the collection the TraceListener at the specified index.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Copies a section of the current TraceListenerCollection to the specified array of TraceListener objects.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

Gets a value indicating whether access to the TraceListenerCollection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

Gets an object that can be used to synchronize access to the TraceListenerCollection.

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

Adds a trace listener to the TraceListenerCollection.

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

Determines whether the TraceListenerCollection contains a specific object.

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

Determines the index of a specific object in the TraceListenerCollection.

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

Inserts a TraceListener object at the specified position in the TraceListenerCollection.

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

Gets a value indicating whether the TraceListenerCollection has a fixed size.

IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

Gets a value indicating whether the TraceListenerCollection is read-only

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

Gets or sets the TraceListener at the specified index in the TraceListenerCollection.

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

Removes an object from the TraceListenerCollection.

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also