EventListeners for Hardware Resources
10/25/2020
EventSources and EventListeners
.net core infrastructure for event counters consists of a good couple of classes. This post will details the classes and their responbility when it comes to in-process event counting. I am writing this post by reverse engineering part of System.Diagnostics
and System.Diagnostics.Tracing
from their GitHub repo.
EventSource
, EventListener
, EventCounter
(DiagnosticCounter
), CounterGroup
, EventDispatcher
. Not all of these classes are relevant when simply creating or consuming counters, but we need a good understanding when it comes to testing. The purpose of this post is to detail their responsibilities and their internals.
Generally, to create our own set of counters, we would need to derive from EventSource
class. In this class typically in the constructor we can create counters such as PollingCounter, IncrementingCounter, etc. Each counter has a name and a reference to containing EventSource
derived class.