I'm using ETW, and logging some events that have stop & stop opcodes, e.g.
[Event(1, Task = Tasks.ActivateTask, Opcode = EventOpcode.Start)]
public void ActivateTaskStart(string TaskName)
{
if (IsEnabled())
{
WriteEvent(1, TaskName);
}
}
[Event(2, Task = Tasks.ActivateTask, Opcode = EventOpcode.Stop)]
public void ActivateTaskStop(string TaskName)
{
if (IsEnabled())
{
WriteEvent(2, TaskName);
}
}
If I have two threads that are both logging ActivateTask start/stop events, how do I make sure the events are correctly paired up? e.g. If I have:
then later
from my reading of the ETW docs, it will default to assuming that the Stop event belongs to the most recent, unpaired, Start event - but I want to make sure I'm linking the correct Start/Stop events.
Is that possible? If so, how?
To make this more complicated, there's a chance that the Start and Stop events might be coming from different threads (if I need to, I should be able to make the threads sticky).
This is called ActivityTrackig and works since .Net 4.6. To get this working automatically, you can't use own Thread implementations, you have to wrap all calls into System.Threading.Tasks.Task calls.