Add log4net to the sample application
It is also very simple to integrate log4net into the sample application. Just add log4net package (current version is 1.2.13) with a NuGet to the project.
Add <log4net> section to the App.config file
Create a logger in code.
Note that log4net doesn't have Null appender out from the box. But it is not difficult to create it by inheriting from AppenderSkeleton with an empty void Append(LoggingEvent loggingEvent) override method:
My experiments showed the following key options that influence on log4net performance out of the box:
- NullAppender that was implemented above is the fastest appender. It shows the general performance of logging internals and can be used to compare log4net with other similar components (e.g. NLog).
- FileAppender is used to store logging messages to the specified file, but performs much slower than NullAppender
- RollingFileAppender is usefull to separate logging messages by date, time or file size attribute, but performs a little bit slower than FileAppender
Performance of the NullAppender
Performance of the FileAppender and RollingFileAppender
- log4net doesn't support NullAppender and async logging out of box, but it could be extended by inheriting from AppenderSkeleton or ForwardingAppender
- NullAppender performance shows how fast log4net internals works. It looks much better in comparison with NLog!
- Both FileAppender and RollingFileAppender performs 3 times faster than NLog File target equivalent
- Both FileAppender and RollingFileAppender throughput 3 times greater than NLog File target equivalent