Recently, I needed a simple way to redirect all Log4Net messages, that an application logs, to be redirected as ETW events. Now, usually that is not what you want to do. ETW events should be typed and specific. However, simply sending all log messages of an application as ETW events also has some merit. For example, you can correlate them with other events (like memory allocations, file I/O, .NET CLR events, etc.) that an application produces to get a better understanding of certain issues.
There are lots of tutorials and examples on the internet that explain what ETW is, how it works, how you use it and how you can view events and other data produced by it. Hence, here I will only show the implementation of the appender itself.
First we need a class that represents the event source (you may want to use a better name, here we go wit “MyApp-Logging”):
Then, we need the actual appender implementation, that makes use of this event source:
As you can see, the most work is actually mapping the Log4Net levels to the respective ETW event levels and issuing the events based on the information of the logging event.
Use this is a starting point for more involved events.