Export (0) Print
Expand All

EventListener Class

.NET Framework 4.5

Provides methods for enabling and disabling events from event sources.

System.Object
  System.Diagnostics.Tracing.EventListener

Namespace:  System.Diagnostics.Tracing
Assembly:  mscorlib (in mscorlib.dll)

public abstract class EventListener : IDisposable

The EventListener type exposes the following members.

  NameDescription
Protected methodSupported in .NET for Windows Store appsEventListenerCreates a new instance of the EventListener class.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsDisableEventsDisables all events for the specified event source.
Public methodSupported in .NET for Windows Store appsDisposeReleases the resources used by the current instance of the EventListener class.
Public methodSupported in .NET for Windows Store appsEnableEvents(EventSource, EventLevel)Enables events for the specified event source that has the specified verbosity level or lower.
Public methodSupported in .NET for Windows Store appsEnableEvents(EventSource, EventLevel, EventKeywords)Enables events for the specified event source that has the specified verbosity level or lower, and matching keyword flags.
Public methodSupported in .NET for Windows Store appsEnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String, String>)Enables events for the specified event source that has the specified verbosity level or lower, matching event keyword flag, and matching arguments.
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodStatic memberSupported in .NET for Windows Store appsEventSourceIndexGets a small non-negative number that represents the specified event source.
Protected methodSupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsOnEventSourceCreatedCalled for all existing event sources when the event listener is created and when a new event source is attached to the listener.
Protected methodSupported in .NET for Windows Store appsOnEventWrittenCalled whenever an event has been written by an event source for which the event listener has enabled events.
Public methodSupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

An event listener represents the target for all events generated by event source (EventSource object) implementations in the current application domain. When a new event listener is created, it is logically attached to all event sources in that application domain.

NoteNote

This type implements the IDisposable interface. When you have finished using the type, you must dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

An event listener can enable or disable on a per-current event source basis by using event levels (EventLevel) and event keywords (EventKeywords) to further restrict the set of events to be sent to the listener. The listener can also send arbitrary commands to a specific current event source by using the SendCommand method. The meanings of the commands are specific to the implementation of the event source.

If the Guid property in the EventSource object that is used to enable or disable events is Empty, all event sources in the application domain are affected.

Multiple event listeners can be defined in a single application domain. Each listener is logically independent of the other listeners so that events that are enabled or disabled by one listener affect only that listener. It is possible for commands sent with the SendCommand method to do a semantic operation (such as a garbage collection or flushing data) that affects the other listeners, but this is the exception rather than the rule.

Each event source keeps a list of event listeners that it sends events to. A set of filtering criteria is associated with each event source-listener pair. These criteria determine the events that listener will receive for the current event source. Listeners receive the events on their OnEventWritten method. Therefore, subclasses of EventListener must override this method to do something useful with the data.

When a new event source is created, the OnEventSourceCreated method is called. Every current event source gets exactly one OnEventSourceCreated call for every current event source that can send it log messages. When an event listener is created, a series of OnEventSourceCreated calls are made to notify the new listener of all the event sources that existed before the listener was created.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, 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.
Show:
© 2014 Microsoft