EventListener 類別

定義

提供啟用和停用事件來源事件的方法。Provides methods for enabling and disabling events from event sources.

public ref class EventListener abstract : IDisposable
public ref class EventListener : IDisposable
public abstract class EventListener : IDisposable
public class EventListener : IDisposable
type EventListener = class
    interface IDisposable
Public MustInherit Class EventListener
Implements IDisposable
Public Class EventListener
Implements IDisposable
繼承
EventListener
實作

備註

事件接聽 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. 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。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. 接聽程式也可以使用方法,將任意命令傳送到特定的目前事件來源 SendCommandThe 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. 接聽程式會接收其方法上的事件 OnEventWrittenListeners 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 類別的新執行個體。Creates a new instance of the EventListener class.

方法

DisableEvents(EventSource)

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

Dispose()

EventListener 類別的目前執行個體所使用的資源釋出。Releases the resources used by the current instance of the EventListener class.

EnableEvents(EventSource, EventLevel)

啟用具有指定詳細資訊層級或更低之指定事件來源的事件。Enables events for the specified event source that has the specified verbosity level or lower.

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>)

啟用具有指定詳細資訊層級或更低且符合關鍵字旗標及引數之指定事件來源的事件。Enables events for the specified event source that has the specified verbosity level or lower, matching event keyword flag, and matching arguments.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
EventSourceIndex(EventSource)

取得小的非負數,其代表指定的事件來源。Gets a small non-negative number that represents the specified event source.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
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)

每當事件由事件接聽程式已啟用事件的事件來源寫入時呼叫。Called whenever an event has been written by an event source for which the event listener has enabled events.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

EventSourceCreated

發生於將事件來源 (EventSource 物件) 附加至發送器時。Occurs when an event source (EventSource object) is attached to the dispatcher.

EventWritten

發生於事件已由事件接聽程式已啟用事件的事件來源 (EventSource 物件) 寫入時。Occurs when an event has been written by an event source (EventSource object) for which the event listener has enabled events.

適用於