EventSource.WriteEventWithRelatedActivityId(Int32, Guid, Object[]) メソッド

定義

現在のアクティビティが別のアクティビティに関連していることを示すイベントを書き込みます。

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 、転送イベントをログに記録します。 現在のスレッドのアクティビティは イベントと共にログに記録され、これにより、イベントのコンシューマーによって 2 つのアクティビティが関連付けられます。

この関数を呼び出す ETW イベント メソッドは、次のガイドラインに従う必要があります。

  1. 最初のパラメーターを 名前付き relatedActivityIdとしてGuid指定します。

  2. プロパティとして または ReceiveSendEventAttribute.Opcode指定します。

  3. イベント ID を渡し、その後に関連する ID GUID を渡し、その後にイベント メソッドが渡されるすべてのパラメーターを同じ順序で呼び出 WriteEventWithRelatedActivityId します。

が使用されていない場合 args は、結果として ETW を呼び出すために空の配列に変換されます。

適用対象