EventSource.WriteEvent 方法

定义

通过使用提供的事件标识符和可选自变量写入事件。

重载

WriteEvent(Int32, String, String, String)

通过使用提供的事件标识符和字符串自变量写入事件。

WriteEvent(Int32, String, Int32, Int32)

通过使用提供的事件标识符和自变量写入事件。

WriteEvent(Int32, Int64, Int64, Int64)

通过使用提供的事件标识符和 64 位参数写入事件。

WriteEvent(Int32, Int32, Int32, Int32)

通过使用提供的事件标识符和 32 位整数参数写入事件。

WriteEvent(Int32, String, String)

通过使用提供的事件标识符和字符串自变量写入事件。

WriteEvent(Int32, String, Int64)

通过使用提供的事件标识符和自变量写入事件。

WriteEvent(Int32, String, Int32)

通过使用提供的事件标识符和自变量写入事件。

WriteEvent(Int32, Int64, String)

使用提供的事件标识符、64 位整数和字符串自变量写入事件。

WriteEvent(Int32, Int64, Int64)

通过使用提供的事件标识符和 64 位参数写入事件。

WriteEvent(Int32, Int32, Int32)

通过使用提供的事件标识符和 32 位整数参数写入事件。

WriteEvent(Int32, Int32, String)

使用提供的事件标识符、32 位整数和字符串自变量写入事件。

WriteEvent(Int32, String)

通过使用提供的事件标识符和字符串自变量写入事件。

WriteEvent(Int32, Object[])

通过使用提供的事件标识符和自变量数组写入事件。

WriteEvent(Int32, Int64)

通过使用提供的事件标识符和 64 位整数自变量写入事件。

WriteEvent(Int32, Int32)

通过使用提供的事件标识符和 32 位整数参数写入事件。

WriteEvent(Int32, EventSource+EventSourcePrimitive[])

使用提供的事件标识符和可变数量的事件源基元写入事件。

WriteEvent(Int32, Byte[])

通过使用提供的事件标识符和字节数组自变量写入事件。

WriteEvent(Int32)

通过使用提供的事件标识符写入事件。

WriteEvent(Int32, Int64, Byte[])

使用指定的标识符、64 位整数和字节数组参数写入事件数据。

注解

方法 WriteEvent 使用字符串参数和整数参数的组合提供重载。 如果这些组合都不匹配调用的参数,则编译器将使用 EventSource.WriteEvent(Int32, Object[]) 重载,该重载比其他重载慢得多。 有关详细信息,请参阅重载页。

在所有情况下, eventid 参数应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,该方法 EventId 传递 和 与实现的方法相同的参数,类似于以下示例。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

还可以使用 WriteEventCore 方法创建自定义重载。

重要

类型 string 为 的事件参数不应包含 \0 字符。 它们是不支持的字符,可能会导致事件有效负载分析程序出现问题。

WriteEvent(Int32, String, String, String)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和字符串自变量写入事件。

protected:
 void WriteEvent(int eventId, System::String ^ arg1, System::String ^ arg2, System::String ^ arg3);
protected void WriteEvent (int eventId, string arg1, string arg2, string arg3);
protected void WriteEvent (int eventId, string? arg1, string? arg2, string? arg3);
member this.WriteEvent : int * string * string * string -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As String, arg2 As String, arg3 As String)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
String

一个字符串自变量。

arg2
String

一个字符串自变量。

arg3
String

一个字符串自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, String, Int32, Int32)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和自变量写入事件。

protected:
 void WriteEvent(int eventId, System::String ^ arg1, int arg2, int arg3);
protected void WriteEvent (int eventId, string arg1, int arg2, int arg3);
protected void WriteEvent (int eventId, string? arg1, int arg2, int arg3);
member this.WriteEvent : int * string * int * int -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As String, arg2 As Integer, arg3 As Integer)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
String

一个字符串自变量。

arg2
Int32

32 位整数参数。

arg3
Int32

32 位整数参数。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int64, Int64, Int64)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和 64 位参数写入事件。

protected:
 void WriteEvent(int eventId, long arg1, long arg2, long arg3);
protected void WriteEvent (int eventId, long arg1, long arg2, long arg3);
member this.WriteEvent : int * int64 * int64 * int64 -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Long, arg2 As Long, arg3 As Long)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int64

64 位整数自变量。

arg2
Int64

64 位整数自变量。

arg3
Int64

64 位整数自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int32, Int32, Int32)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和 32 位整数参数写入事件。

protected:
 void WriteEvent(int eventId, int arg1, int arg2, int arg3);
protected void WriteEvent (int eventId, int arg1, int arg2, int arg3);
member this.WriteEvent : int * int * int * int -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Integer, arg2 As Integer, arg3 As Integer)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int32

一个整数参数。

arg2
Int32

一个整数参数。

arg3
Int32

一个整数参数。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, String, String)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和字符串自变量写入事件。

protected:
 void WriteEvent(int eventId, System::String ^ arg1, System::String ^ arg2);
protected void WriteEvent (int eventId, string arg1, string arg2);
protected void WriteEvent (int eventId, string? arg1, string? arg2);
member this.WriteEvent : int * string * string -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As String, arg2 As String)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
String

一个字符串自变量。

arg2
String

一个字符串自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, String, Int64)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和自变量写入事件。

protected:
 void WriteEvent(int eventId, System::String ^ arg1, long arg2);
protected void WriteEvent (int eventId, string arg1, long arg2);
protected void WriteEvent (int eventId, string? arg1, long arg2);
member this.WriteEvent : int * string * int64 -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As String, arg2 As Long)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
String

一个字符串自变量。

arg2
Int64

64 位整数自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, String, Int32)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和自变量写入事件。

protected:
 void WriteEvent(int eventId, System::String ^ arg1, int arg2);
protected void WriteEvent (int eventId, string arg1, int arg2);
protected void WriteEvent (int eventId, string? arg1, int arg2);
member this.WriteEvent : int * string * int -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As String, arg2 As Integer)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
String

一个字符串自变量。

arg2
Int32

32 位整数参数。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int64, String)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

使用提供的事件标识符、64 位整数和字符串自变量写入事件。

protected:
 void WriteEvent(int eventId, long arg1, System::String ^ arg2);
protected void WriteEvent (int eventId, long arg1, string arg2);
protected void WriteEvent (int eventId, long arg1, string? arg2);
member this.WriteEvent : int * int64 * string -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Long, arg2 As String)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int64

64 位整数自变量。

arg2
String

一个字符串自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(Int64 arg1, string arg2)
{
    base.WriteEvent(2, arg1, arg2);
}

适用于

WriteEvent(Int32, Int64, Int64)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和 64 位参数写入事件。

protected:
 void WriteEvent(int eventId, long arg1, long arg2);
protected void WriteEvent (int eventId, long arg1, long arg2);
member this.WriteEvent : int * int64 * int64 -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Long, arg2 As Long)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int64

64 位整数自变量。

arg2
Int64

64 位整数自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int32, Int32)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和 32 位整数参数写入事件。

protected:
 void WriteEvent(int eventId, int arg1, int arg2);
protected void WriteEvent (int eventId, int arg1, int arg2);
member this.WriteEvent : int * int * int -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Integer, arg2 As Integer)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int32

一个整数参数。

arg2
Int32

一个整数参数。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(int arg1, int arg2, int arg3)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int32, String)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

使用提供的事件标识符、32 位整数和字符串自变量写入事件。

protected:
 void WriteEvent(int eventId, int arg1, System::String ^ arg2);
protected void WriteEvent (int eventId, int arg1, string arg2);
protected void WriteEvent (int eventId, int arg1, string? arg2);
member this.WriteEvent : int * int * string -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Integer, arg2 As String)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int32

32 位整数自变量。

arg2
String

一个字符串自变量。

适用于

WriteEvent(Int32, String)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和字符串自变量写入事件。

protected:
 void WriteEvent(int eventId, System::String ^ arg1);
protected void WriteEvent (int eventId, string arg1);
protected void WriteEvent (int eventId, string? arg1);
member this.WriteEvent : int * string -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As String)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
String

一个字符串自变量。

示例

下面的示例演示如何使用此方法重载编写事件。 此代码示例是为 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

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Object[])

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和自变量数组写入事件。

protected:
 void WriteEvent(int eventId, ... cli::array <System::Object ^> ^ args);
protected void WriteEvent (int eventId, params object[] args);
protected void WriteEvent (int eventId, params object?[] args);
member this.WriteEvent : int * obj[] -> unit
Protected Sub WriteEvent (eventId As Integer, ParamArray args As Object())

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

args
Object[]

一个 对象的数组。

注解

默认情况下,如果调用的参数与其他方法重载之一不匹配,编译器将调用此重载。 此重载比其他重载慢得多,因为它执行以下操作:

  1. 它分配一个数组来保存变量参数。

  2. 它将每个参数强制转换为对象 (这会导致基元类型分配) 。

  3. 它将这些对象分配给数组。

  4. 它调用 函数,该函数随后确定每个参数的类型,以便可以针对 ETW 对其进行序列化。

跟踪低容量事件时,此重载的高开销并不显著,因为仅在启用提供程序时才使用 方法。 但是,对于大容量事件,性能开销可能很大。 通过使用 方法创建更快的新重载WriteEventCore,可以避免EventSource.WriteEvent将 用于大容量有效负载。

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int64)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和 64 位整数自变量写入事件。

protected:
 void WriteEvent(int eventId, long arg1);
protected void WriteEvent (int eventId, long arg1);
member this.WriteEvent : int * int64 -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Long)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int64

64 位整数自变量。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int32)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和 32 位整数参数写入事件。

protected:
 void WriteEvent(int eventId, int arg1);
protected void WriteEvent (int eventId, int arg1);
member this.WriteEvent : int * int -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Integer)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int32

一个整数参数。

示例

下面的示例演示如何使用此方法重载编写事件。 此代码示例是为 EventSource 类提供的一个更大示例的一部分。

[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

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,传递 EventId 和与实现的方法相同的参数,如以下示例所示。

[Event(2, Level = EventLevel.Informational)]
public void Info1(int  arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, EventSource+EventSourcePrimitive[])

Source:
EventSource.cs
Source:
EventSource.cs

使用提供的事件标识符和可变数量的事件源基元写入事件。

protected:
 void WriteEvent(int eventId, ... cli::array <System::Diagnostics::Tracing::EventSource::EventSourcePrimitive> ^ args);
protected void WriteEvent (int eventId, params System.Diagnostics.Tracing.EventSource.EventSourcePrimitive[] args);
member this.WriteEvent : int * System.Diagnostics.Tracing.EventSource.EventSourcePrimitive[] -> unit
Protected Sub WriteEvent (eventId As Integer, ParamArray args As EventSource.EventSourcePrimitive())

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

args
EventSource.EventSourcePrimitive[]

事件源基元。

注解

这是用于编写事件的 varargs 帮助程序。 它确实会创建一个数组并装箱所有参数,因此效率相对较低,只应用于相对罕见的事件 (例如,) 小于每秒 100 个。 如果速率快于此速度,请使用 WriteEventCore(Int32, Int32, EventSource+EventData*) 为特定方法签名创建快速帮助程序。 即使将此用于罕见事件,此调用也应该由IsEnabled()检查保护,以便在 EventSource 不处于活动状态时不会发出 varargs 调用。

适用于

WriteEvent(Int32, Byte[])

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符和字节数组自变量写入事件。

protected:
 void WriteEvent(int eventId, cli::array <System::Byte> ^ arg1);
protected void WriteEvent (int eventId, byte[] arg1);
protected void WriteEvent (int eventId, byte[]? arg1);
member this.WriteEvent : int * byte[] -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Byte())

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Byte[]

字节数组参数。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,该方法 EventId 传递 和 与实现的方法相同的参数,类似于以下示例。

[Event(2, Level = EventLevel.Informational)]
public void Info1(byte[] arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

通过使用提供的事件标识符写入事件。

protected:
 void WriteEvent(int eventId);
protected void WriteEvent (int eventId);
member this.WriteEvent : int -> unit
Protected Sub WriteEvent (eventId As Integer)

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

示例

以下示例演示如何使用此方法重载编写事件。 此代码示例是为 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

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,该方法 EventId 传递 和 与实现的方法相同的参数,类似于以下示例。

[Event(2, Level = EventLevel.Informational)]
public void Info1(string arg1)
{
    base.WriteEvent(2, arg1);
}

适用于

WriteEvent(Int32, Int64, Byte[])

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

使用指定的标识符、64 位整数和字节数组参数写入事件数据。

protected:
 void WriteEvent(int eventId, long arg1, cli::array <System::Byte> ^ arg2);
protected void WriteEvent (int eventId, long arg1, byte[] arg2);
protected void WriteEvent (int eventId, long arg1, byte[]? arg2);
member this.WriteEvent : int * int64 * byte[] -> unit
Protected Sub WriteEvent (eventId As Integer, arg1 As Long, arg2 As Byte())

参数

eventId
Int32

事件标识符。 该值应介于 0 到 65535 之间。

arg1
Int64

64 位整数自变量。

arg2
Byte[]

字节数组参数。

注解

eventid 应大于 0 或小于 65535,否则操作中可能会出现错误。 如果确实发生错误,可以通过检查调试器的输出流来获取有关错误源的详细信息(如果已将调试器附加到进程触发事件)。 如果发生错误的事件源上有 ETW 侦听器,还可以查找 ETW 事件流中报告的错误。

实现在 派生类中 EventSource标识为 ETW 事件的方法时。 必须调用基类 WriteEvent 方法,该方法 EventId 传递 和 与实现的方法相同的参数,类似于以下示例。

[Event(2, Level = EventLevel.Informational)]
public void Info1(Int64 arg1, Byte[] arg2)
{
    base.WriteEvent(2, arg1, arg2);
}

适用于