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

注解

将此属性应用于在 -derived 类上 EventSource定义的 ETW 事件方法时,必须在基类上调用 WriteEvent 该方法,传递事件 ID,后跟传递定义的方法相同的参数。 应遵循以下示例所示的模式。

构造函数

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)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于