Better Tracing And Instrumentation For .NET Apps
EventSource and EventListener, introduced in .NET 4.5, provide a simple mechanism for applications to trace their events in Event Tracing for Windows (ETW). Combined with a analysis tool such as PerfView, this allows for better tracing of .NET apps.
.NET 4.5 introduces the EventSource class which provides a base class for developers to inherit and write their own Event Sources. Developers can then add a new method for every different type of event they want to log - these methods can be called from the application at the appropriate locations. Internally, these methods will call the base method WriteEvent() which in-turn sends the events to EventListeners that have subscribed, including the built-in listener that sends its logging messages to the ETW. Vance Morrison describes this in detail.
As mentioned in a reference guide “Strongly Typed Events (EasyETW)” posted by Vance -
ETW is a high performance eventing system for windows which is used extensively in both the windows kernel as well as many windows subsystems. These built-in ETW sources provide wonderful ‘low level’ value (indicating where CPU, Disk, and network activities occur), and EventSource builds on this by allowing programmers to mark ‘high level’ semantic actions (like a user command, or a high level event), and thus assign resource consumption to high level tasks.
You can also implement custom EventListeners which can do things other than sending info to the ETW – for example, if for silverlight apps, you want to send the trace data over the network to the host machine.
PerfView is a performance analysis tool from Microsoft. Deployed as a single exe, it supports both CPU and Memory investigations of any application, but it also has some useful features especially for profiling managed code. Learn more about how to use this tool through these videos posted by Vance.