Another toy in my SANDBOX to remember how to log in best performance, when I need to do it
In this project I have all the usual log methods and in this sample I want demonstrate the difference between them.
I log in 3 methods, the famous Log4net, the classic Diagnostic.Debug and in ETW mode. Below the code of the test, it is very simple but I wrote it to understand the importance of the correct use of logging strategies.
This code cycles int cycles = 10000; , you can modify this variable to understand in deep the log behavior.
The is because ETW is a very fast method, so you need to increase the cycles to note the differences between the ETW srategies.
Below the results
Log4Net is the slower, naturally the best is ETW and second is Diagnostic.Debug, note the configuration in app.config for Diagnostic.Debug.
I use an asynchronous listener to capture the Diagnostic.Debug events, you can write all of this event in a Console or database or file, in this case I use a Console
Many developer use the Diagnostic.Debug without to use an asynchronous listener and this is a big problem in term of performance.
Below observe the difference without an asynchronous listener.
This is the importance to use the listeners during log, with regardless from log method.
Another important aspect is the use of the message logging, now I increase the cycles to 1.000.000.
Observe IN RED the result and how can change the value passing a “string” + variable and pass a “string” + “string”.
Observe IN BLUE the difference between the Log4Net and Diagnostic.Debug in asynchronous listener.
Last consideration, if you need to log in high performance the best way is ETW, ETW is simple to use but…
use essential calls , don’t use any other class or component more…
the rule must to be one line of code = one event in ETW
in toy you can see a simple and essential use of ETW, you can use this to make all of your experiments.
All the code here
others toys in my SANDOX here