开发者

Which is the quickest appender for log4Net?

Which is the quickest appender开发者_StackOverflow for log4Net apart from ConsoleAppender?


Checkout the BufferingForwardingAppender. We use this which forwards to a RollingFileAppender. It batches the writes and allows the code to continue without waiting for the write. We setup an Evaluator to force a flush at the WARN threshold and set lossy to false so we don't miss any messages.

<appender name="BufferingForwardingAppender" type="log4net.Appender.BufferingForwardingAppender">
    <bufferSize value="512" />
    <lossy value="false" />
    <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="WARN"/>
    </evaluator>
    <appender-ref ref="RollingFileAppender" />
</appender>


You could write a log4Net equivalent of NullAppender, which would be very fast... (Oops - I originally thought the question was about log4j; the same advice applies though.)

Of course, that wouldn't do anything useful - which leads me to wonder why you're placing so much importance on speed. The normal approach is to work out what you need, then benchmark/profile it to check whether it performs adequately. I suspect that you'll be swamped with more data than you can usefully process before it actually becomes a bottleneck. Do you have a known performance problem with logging?


you should consider

  1. writing to file is much faster than writing to console
  2. I guess your problem is with the pre-production (ceating the log data and then not using it) use log.canLog to make sure you can log before you create your data (this is usually the big time consumer)
  3. check you're not using all kinds of fields that are time consuming like current credentials of user etc...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜