How do I create an asynchronous wrapper for log4net?

后端 未结 6 861
轮回少年
轮回少年 2020-12-13 04:34

By default, log4net is a synchronous logging mechanism, and I was wondering if there was a way to have asynchronous logging with log4net?

6条回答
  •  臣服心动
    2020-12-13 05:04

    Some of the ideas here are incorrect and result in invalid/stale data, out of order logging or very bad performance. For instance the accepted answer suggests using the log4net AsyncAppender which uses the ThreadPool resulting in out of order entries which might not be a problem for some but I certainly want my log events to be one after another it also can have terrible performance and put too much strain on the ThreadPool also it does not batch the log entries. The answer suggested by Jonathan is certainly a much better solution but still lacks optimal performance.

    A good example of how this should be implemented can be found HERE and the benchmarking results and the explanation HERE.

    Another good feature of this solution is that it has been implemented as a Forwarder not an Appender allowing the user to include more than one Appender and log to each of them at the same time.

提交回复
热议问题