EventAttribute 类

定义

指定事件的附加事件架构信息。Specifies additional event schema information for an event.

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

示例

下面的示例演示如何使用 EventAttribute 类定义各种事件。The following example shows how to use the EventAttribute class to define a variety of events. 此代码示例是为 EventSource 类提供的更大示例的一部分。This code example is part of a larger example provided for the EventSource class.

[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 方法,传递事件 ID,后跟与定义的方法传递的参数相同的参数。When you apply this attribute to an ETW event method defined on an EventSource-derived class, you must call the WriteEvent method on the base class, passing the event ID, followed by the same arguments as the defined method is passed. 应遵循以下示例中所示的模式。You should follow the pattern shown in the following examples.

构造函数

EventAttribute(Int32)

使用指定的事件标识符初始化 EventAttribute 类的新实例。Initializes a new instance of the EventAttribute class with the specified event identifier.

属性

ActivityOptions

指定活动的开始和结束事件的行为。Specifies the behavior of the start and stop events of an activity. 活动是应用中开始和停止之间的时间区域。An activity is the region of time in an app between the start and the stop.

Channel

获取或设置应在其中写入事件的附加事件日志。Gets or sets an additional event log where the event should be written.

EventId

获取或设置事件的标识符。Gets or sets the identifier for the event.

Keywords

获取或设置事件的关键字。Gets or sets the keywords for the event.

Level

获取或设置事件的级别。Gets or sets the level for the event.

Message

获取或设置事件的消息。Gets or sets the message for the event.

Opcode

获取或设置事件的操作代码。Gets or sets the operation code for the event.

Tags

获取或设置此 EventTags 对象的 EventAttribute 值。Gets or sets the EventTags value for this EventAttribute object. 事件标记是记录事件时传递的用户定义值。An event tag is a user-defined value that is passed through when the event is logged.

Task

获取或设置事件的任务。Gets or sets the task for the event.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)
Version

获取或设置事件的版本。Gets or sets the version of the event.

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

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

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

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

(继承自 Object)
ToString()

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

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于