Provides methods for enabling and disabling events from event sources.
public ref class EventListener abstract : IDisposable
public abstract class EventListener : IDisposable
type EventListener = class interface IDisposable
Public MustInherit Class EventListener Implements IDisposable
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.
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
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.
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 listener 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.
|EventListener() EventListener() EventListener() EventListener()||
Creates a new instance of the EventListener class.
|EventSourceCreated EventSourceCreated EventSourceCreated EventSourceCreated||
Occurs when an event source (EventSource object) is attached to the dispatcher.
|EventWritten EventWritten EventWritten EventWritten||
Occurs when an event has been written by an event source (EventSource object) for which the event listener has enabled events.