EnableEvents for one EventListener seems to impact another EventListener
@mdh1418 is already working on this.
Since Jun 24, 2025.
Assessment
This issue has not been assessed yet.
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
EventListenercallsEnableEventsfor anEventSourcewithEventCounterIntervalSecset in the args parameter,EventCountersfrom thisEventSourcewill be sent to ALLEventListener. WhenEventCounterIntervalSecis not set,EventCountersevents 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
EventListenerwhich enabled events for theEventSourcedisable events for theEventSourcewillEventCountersfor thatEventSourcestop 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
EventListenerto callEnableEventsfor anEventSourcewithEventCounterIntervalSecset in the args parameter will have its value used for the interval. Subsequent calls with differentEventCounterIntervalSecwill 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
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·