开发者

What's the advantage of [insert your favorite logging library here] over System.Diagnostics.Trace?

开发者 https://www.devze.com 2023-03-07 04:29 出处:网络
Apologies if I overlooked it but I couldn\'t immediately find a similar question on SO. .Net comes with some built-in logging capabilities (essentially, System.Diagnostics.Debug and System.Diagnostic

Apologies if I overlooked it but I couldn't immediately find a similar question on SO.

.Net comes with some built-in logging capabilities (essentially, System.Diagnostics.Debug and System.Diagnostics.Trace).

Is there a goo开发者_开发知识库d reason not to use these built-in facilities for logging purposes in a typical LOB application, and instead use log4net, NLog, EntLib logging block or [insert your favourite logging library here]?

EDIT: note that I am more interested in pinpointing the shortcomings of System.Diagnostics w.r.t. logging capabilities, rather than the features of the different logging libraries.


I prefer to use NLog or log4net because it gives me:

  1. Logging targets. I can chose the best for certain purpose without changing any bit of logging code
  2. I can log the informations that I need at certain situation thanks to Log Levels
  3. I can format my Log Entry the way I like, also in different ways for diferent Targets
  4. Performance is quite ok, thanks for batching
  5. Im not inventing the wheel
  6. I can reause this many times


Being able to send your logs to multiple endpoints (syslog, database, event log, etc) can be useful.


I use log4net and it's advantages are that in configuration files you can choose what level of logging you require (Critical, Error, Warning, Information, Debug) and you get things like email logging and rolling log files for free.


For .net, I like using http://netcommon.sourceforge.net/doc-latest/reference/html/logging.html. It's basically a wrapper layer above, so underneath, you can switch logging engines easily. It's very log4net like though.

There is also:

http://commons.apache.org/logging/guide.html

0

精彩评论

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

关注公众号