Επεξεργασία

Κοινή χρήση μέσω


EventSource.WriteEventWithRelatedActivityId(Int32, Guid, Object[]) Method

Definition

Writes an event that indicates that the current activity is related to another activity.

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())

Parameters

eventId
Int32

An identifier that uniquely identifies this event within the EventSource.

relatedActivityIdchildActivityID
Guid

The related activity identifier.

args
Object[]

An array of objects that contain data about the event.

Examples

The following code example shows how you might can specify an event source that calls 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);
            }
        }
    }

Remarks

The WriteEventWithRelatedActivityId method logs a transfer event. The activity of the current thread is logged with the event, and this allows two activities to be related by a consumer of events.

Your ETW event method calling this function must follow these guidelines:

  1. Specify the first parameter as a Guid named relatedActivityId.

  2. Specify either Send or Receive as the EventAttribute.Opcode property.

  3. Call WriteEventWithRelatedActivityId passing in the event ID, followed by the related ID GUID, followed by all the parameters the event method is passed, in the same order.

If args is not used, it is converted to an empty array for the resulting call to ETW.

Applies to