Question

I need a logging framework in my application. I have two candidates: Log4Net and Logging from Application Block. Which is better? any specific advantage to any of them?

Thanks

Was it helpful?

Solution

My opinion ... Log4Net works, performs well and is stable (perhaps too stable given frequency of releases if you know what I mean).

If you need logging it is highly unlikely that you don't need other functionality exposed by Enterprise Library, you'd be on the Microsoft road map, benefit from regular updates, have tool support (e.g. configuration tool) and there is always the much maligned documentation which is far superior than you will get with Open Source.

I think my preference is clear! Enterprise Library all the way.

OTHER TIPS

I have found Log4Net to be simpler to setup and use. The problem with Enterprise Library application blocks is they tend to include everything and the kitchen sink and can make something seemingly simple (like logging) into something really complicated. Also because Log4Net is used with nHibernate which I also use then I already have it there ready to go.

I would go for log4net unless you are already using Enterprise Library for other functionality. I find Enterprise Library to be a bit heavy weight and takes a bit more code to actually do the logging.

log4net has the following advantages;

  • Fast and flexible
  • Hierarchical, named logging categories
  • Multiple logging levels
  • Output to multiple logging targets
  • Dynamic XML Configuration
  • Thread Safe
  • Format of logs is easily changed
  • Proven architecture (log4j)
  • Modular and extensible design
  • Support for multiple frameworks
  • A strong community behind it.

I have been using log4net for a few years now and whenever I need to do something out of the box, I am surprise how easy it ends up being.

Log 4 net is nice: great features, but it takes some time and effort to master the configuration especially when the default outputs do not suffice and you need to extend it.

Enterprise Library is heavy weight, not sure where they are going (there have been some breaking changes between releases especially in the DAB). So I personally stay away from it.

I am currently looking at nLog (heard some very nice things about it)

UPDATE: I am currently loving nlog. One particular thing I would like to mention is the ease of configuring the loglevel from within code. Usage example: - user experiences bug - we ask to set the loglevel to trace (a menu option) and execute the same steps - we ask to email the logfile to us. (another menu option)

A simple example of log4net console app Bellow is the configuration file also

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top