EventAttribute 類別

定義

指定事件的其他事件結構描述資訊。

public ref class EventAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class EventAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type EventAttribute = class
    inherit Attribute
Public NotInheritable Class EventAttribute
Inherits Attribute
繼承
EventAttribute
屬性

範例

下列範例示範如何使用 EventAttribute 類別來定義各種事件。 此程式代碼範例是針對 類別提供的較大範例的 EventSource 一部分。

[Event(1, Message = "Application Failure: {0}", Level = EventLevel.Error, Keywords = Keywords.Diagnostic)]
public void Failure(string message) { WriteEvent(1, message); }
<[Event](1, Message:="Application Failure: {0}", Level:=EventLevel.Error, Keywords:=Keywords.Diagnostic)> _
Public Sub Failure(ByVal message As String)
    WriteEvent(1, message)
End Sub
[Event(2, Message = "Starting up.", Keywords = Keywords.Perf, Level = EventLevel.Informational)]
public void Startup() { WriteEvent(2); }
<[Event](2, Message:="Starting up.", Keywords:=Keywords.Perf, Level:=EventLevel.Informational)> _
Public Sub Startup()
    WriteEvent(2)
End Sub
[Event(3, Message = "loading page {1} activityID={0}", Opcode = EventOpcode.Start,
    Task = Tasks.Page, Keywords = Keywords.Page, Level = EventLevel.Informational)]
public void PageStart(int ID, string url) { if (IsEnabled()) WriteEvent(3, ID, url); }
<[Event](3, Message:="loading page {1} activityID={0}", Opcode:=EventOpcode.Start, Task:=Tasks.Page, Keywords:=Keywords.Page, Level:=EventLevel.Informational)> _
Public Sub PageStart(ByVal ID As Integer, ByVal url As String)
    If IsEnabled() Then
        WriteEvent(3, ID, url)
    End If
End Sub
[Event(4, Opcode = EventOpcode.Stop, Task = Tasks.Page, Keywords = Keywords.Page, Level = EventLevel.Informational)]
public void PageStop(int ID) { if (IsEnabled()) WriteEvent(4, ID); }
<[Event](4, Opcode:=EventOpcode.Stop, Task:=Tasks.Page, Keywords:=Keywords.Page, Level:=EventLevel.Informational)> _
Public Sub PageStop(ByVal ID As Integer)
    If IsEnabled() Then
        WriteEvent(4, ID)
    End If
End Sub

備註

當您將這個屬性套用至衍生類別上 EventSource定義的 ETW 事件方法時,您必須在基類上呼叫 WriteEvent 方法,傳遞事件標識符,後面接著傳遞與已定義方法相同的自變數。 您應該遵循下列範例所示的模式。

建構函式

EventAttribute(Int32)

使用指定的事件識別項,初始化 EventAttribute 類別的新執行個體。

屬性

ActivityOptions

指定活動之開始和停止事件的行為。 活動是應用程式中從開始到停止之間的時間區域。

Channel

取得或設定應該寫入事件的其他事件記錄檔。

EventId

取得或設定事件的識別項。

Keywords

取得或設定事件的關鍵字。

Level

取得或設定事件的層級。

Message

取得或設定事件的訊息。

Opcode

取得或設定事件的作業程式碼。

Tags

取得或設定此 EventAttribute 物件的 EventTags 值。 事件標記是記錄事件時所傳遞的使用者定義值。

Task

取得或設定事件的工作。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)
Version

取得或設定事件的版本。

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於