EventListener EventListener EventListener EventListener Class

定义

提供用于启用和禁用事件源中事件的方法。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
继承
EventListenerEventListenerEventListenerEventListener
实现

注解

事件侦听器表示生成的事件源的所有事件的目标 (EventSource对象) 的当前应用程序域中的实现。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.

备注

此类型实现IDisposable接口。This type implements the IDisposable interface. 完成后使用的类型的操作后,您必须释放它直接或间接。When you have finished using the type, you must dispose of it either directly or indirectly. 若要直接释放类型,调用其Dispose中的方法try / catch块。To dispose of the type directly, call its Dispose method in a try/catch block. 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 有关详细信息,请参阅中的"使用对象实现 IDisposable"一节IDisposable接口主题。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

事件侦听器可以启用或禁用基于每个当前事件源通过使用事件级别 (EventLevel) 和事件关键字 (EventKeywords) 以进一步限制要发送到侦听器的事件集。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. 侦听器可以还将任意命令发送到特定的当前事件源通过使用SendCommand方法。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.

如果Guid中的属性EventSource对象,用于启用或禁用事件是Empty,应用程序域中的所有事件源受到都影响。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. 很可能与发送命令SendCommand方法来执行操作 (如垃圾回收或刷新数据) 的语义操作会影响其他侦听器,但这是异常而不是规则。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. 侦听器将事件接收其OnEventWritten方法。Listeners receive the events on their OnEventWritten method. 因此,类的子类EventListener必须重写此方法以执行一些有用的数据。Therefore, subclasses of EventListener must override this method to do something useful with the data.

创建新的事件源时,OnEventSourceCreated调用方法。When a new event source is created, the OnEventSourceCreated method is called. 每个当前事件侦听器将获取一个OnEventSourceCreated调用每个当前事件源,可以将其发送日志消息。Every current event listener gets exactly one OnEventSourceCreated call for every current event source that can send it log messages. 创建事件侦听器后,一系列OnEventSourceCreated调用以通知创建侦听器之前存在的所有事件源的新的侦听器。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()

创建 EventListener 类的新实例。Creates a new instance of the EventListener class.

方法

DisableEvents(EventSource) DisableEvents(EventSource) DisableEvents(EventSource) DisableEvents(EventSource)

禁用所有指定事件源的事件。Disables all events for the specified event source.

Dispose() Dispose() Dispose() Dispose()

释放 EventListener 类的当前实例使用的资源。Releases the resources used by the current instance of the EventListener class.

EnableEvents(EventSource, EventLevel) EnableEvents(EventSource, EventLevel) EnableEvents(EventSource, EventLevel) EnableEvents(EventSource, EventLevel)

启动有指定详细级别或较低详细级别的指定事件源的事件。Enables events for the specified event source that has the specified verbosity level or lower.

EnableEvents(EventSource, EventLevel, EventKeywords) EnableEvents(EventSource, EventLevel, EventKeywords) EnableEvents(EventSource, EventLevel, EventKeywords) EnableEvents(EventSource, EventLevel, EventKeywords)

启动有指定详细级别或较低详细级别,且匹配关键字标志的指定事件源的事件。Enables events for the specified event source that has the specified verbosity level or lower, and matching keyword flags.

EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>) EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>) EnableEvents(EventSource, EventLevel, EventKeywords, IDictionary<String,String>) EnableEvents(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.

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

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
EventSourceIndex(EventSource) EventSourceIndex(EventSource) EventSourceIndex(EventSource) EventSourceIndex(EventSource)

获取表示指定事件源的较小非负数。Gets a small non-negative number that represents the specified event source.

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

作为默认哈希函数。Serves as the default hash function.

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

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnEventSourceCreated(EventSource) OnEventSourceCreated(EventSource) OnEventSourceCreated(EventSource) OnEventSourceCreated(EventSource)

当创建该事件侦听器和一个新事件源将附加到侦听器时,为所有现有事件源而调用。Called for all existing event sources when the event listener is created and when a new event source is attached to the listener.

OnEventWritten(EventWrittenEventArgs) OnEventWritten(EventWrittenEventArgs) OnEventWritten(EventWrittenEventArgs) OnEventWritten(EventWrittenEventArgs)

每当事件源写入事件时,用于该事件侦听器以启动事件而调用。Called whenever an event has been written by an event source for which the event listener has enabled events.

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

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

事件

EventSourceCreated EventSourceCreated EventSourceCreated EventSourceCreated

当事件源(EventSource 对象)附加到调度程序时发生。Occurs when an event source (EventSource object) is attached to the dispatcher.

EventWritten EventWritten EventWritten EventWritten

当事件已由事件源(EventSource 对象)写入时发生,其中事件侦听器已为该事件源启用了事件。Occurs when an event has been written by an event source (EventSource object) for which the event listener has enabled events.

适用于