EventSource.WriteEventWithRelatedActivityId(Int32, Guid, Object[]) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
写入一个指示当前活动与其他活动相关的事件。
protected:
void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, ... cli::array <System::Object ^> ^ args);
protected:
void WriteEventWithRelatedActivityId(int eventId, Guid childActivityID, ... cli::array <System::Object ^> ^ args);
protected void WriteEventWithRelatedActivityId (int eventId, Guid relatedActivityId, params object[] args);
protected void WriteEventWithRelatedActivityId (int eventId, Guid relatedActivityId, params object?[] args);
protected void WriteEventWithRelatedActivityId (int eventId, Guid childActivityID, params object[] args);
member this.WriteEventWithRelatedActivityId : int * Guid * obj[] -> unit
member this.WriteEventWithRelatedActivityId : int * Guid * obj[] -> unit
Protected Sub WriteEventWithRelatedActivityId (eventId As Integer, relatedActivityId As Guid, ParamArray args As Object())
Protected Sub WriteEventWithRelatedActivityId (eventId As Integer, childActivityID As Guid, ParamArray args As Object())
参数
- eventId
- Int32
在 EventSource 中唯一标识此事件的标识符。
- relatedActivityIdchildActivityID
- Guid
相关的活动标识符。
- args
- Object[]
包含与事件相关的数据的对象数组。
示例
下面的代码示例演示如何指定调用 WriteEventWithRelatedActivityId的事件源。
[EventSource(Name = "Litware-ProductName-ComponentName")]
public sealed class LitwareComponentNameEventSource : EventSource
{
[Event(1, Task = Tasks.Request, Opcode = EventOpcode.Send)]
public void RequestStart(Guid relatedActivityId, int reqId, string url)
{
WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url);
}
}
<EventSource(Name:="Litware-ProductName-ComponentName")> _
Public NotInheritable Class LitwareComponentNameEventSource
Inherits EventSource
<[Event](1, Task:=Tasks.Request, Opcode:=EventOpcode.Send)> _
Public Sub RequestStart(relatedActivityId As Guid, reqId As Integer, url As String)
WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url)
End Sub
End Class
[EventSource(Name = "Contoso-ProductName-ComponentName")]
public sealed class CustomizedForPerfEventSource : EventSource
{
[Event(1, Task = Tasks.Request, Opcode = EventOpcode.Send)]
public void RequestStart(Guid relatedActivityId, int reqId, string url)
{
if (IsEnabled())
WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url);
}
[NonEvent]
unsafe protected void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId,
int arg1, string arg2)
{
if (IsEnabled())
{
if (arg2 == null) arg2 = string.Empty;
fixed (char* stringBytes = arg2)
{
EventData* descrs = stackalloc EventData[2];
descrs[0].DataPointer = (IntPtr)(&arg1);
descrs[0].Size = 4;
descrs[1].DataPointer = (IntPtr)stringBytes;
descrs[1].Size = ((arg2.Length + 1) * 2);
WriteEventWithRelatedActivityIdCore(eventId,
&relatedActivityId, 2, descrs);
}
}
}
注解
方法 WriteEventWithRelatedActivityId 记录传输事件。 当前线程的活动与 事件一起记录,这允许事件使用者关联两个活动。
调用此函数的 ETW 事件方法必须遵循以下准则:
将第一个 Guid 参数指定为名为
relatedActivityId
的 。Send将 或 Receive 指定为 EventAttribute.Opcode 属性。
调用 WriteEventWithRelatedActivityId 传入事件 ID,后跟相关 ID GUID,后跟传递事件方法的所有参数,顺序相同。
如果未 args
使用 ,则会将其转换为空数组,用于对 ETW 的生成调用。