Description
Description
It seems that calling
EnableEvents
for one instance of an EventListener
is causing another instance to have events enabled for it. Not only that, it seems that disabling an EventSource
for a specific instance of an EventListener
will only stop some events from being written, but not EventCounters
type events.
Reproduction Steps
This shows the behavior where enabling events for one EventListener
enables EventCounters
from the EventSource
and the other EventListener
receives those events.
https://github.com/orange-puff/EventListenerBugRepro/tree/main
This branch shows the behavior where disabling events for an instance of EventListener
that enabled events for this EventSource
only stops some events from being written to it, but not EventCounters
. All EventListener
which enabled events for a given EventSource
need to disable it for EventCounters
events to stop being written to them.
https://github.com/orange-puff/EventListenerBugRepro/tree/disabling-behavior
Expected behavior
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.tracing.eventlistener?view=net-8.0
According to the docs;
Multiple event listeners can be defined in a single application domain. Each listener is logically independent of the other listeners so that events that are enabled or disabled by one listener affect only that listener. It is possible for commands sent with the SendCommand method to do a semantic operation (such as a garbage collection or flushing data) that affects the other listeners, but this is the exception rather than the rule.
This does not seem to be true
Actual behavior
After some experimentation and code reading, I think this is how it works:
- When an
EventListener
callsEnableEvents
for anEventSource
withEventCounterIntervalSec
set in the args parameter,EventCounters
from thisEventSource
will be sent to ALLEventListener
. WhenEventCounterIntervalSec
is not set,EventCounters
events will not be sent.
https://github.com/dotnet/dotnet/blob/main/src/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs#L56 - only after all
EventListener
which enabled events for theEventSource
disable events for theEventSource
willEventCounters
for thatEventSource
stop being sent
https://github.com/dotnet/dotnet/blob/main/src/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs#L81 - The first
EventListener
to callEnableEvents
for anEventSource
withEventCounterIntervalSec
set in the args parameter will have its value used for the interval. Subsequent calls with differentEventCounterIntervalSec
will not be
https://github.com/dotnet/dotnet/blob/main/src/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs#L163
used### Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response