Wednesday, April 2, 2008

Is Enterprise Logging Application Block the best choice for Logging?

I've been using Log4Net for quite some time now, but I recently came across a new logging framework called Microsoft's Enterprise Logging Application Block. That is quite a mouthful, but it sounds promising. The Logging Application Block is part of a collection of other application blocks that is called the Enterprise Library. The Enterprise Library contains eight application blocks:

  • Caching
  • Cryptography
  • Data Access
  • Exception Handling
  • Logging
  • Policy Injection
  • Security
  • Validation

Let's see how the Logging Application Block compares to Log4Net. For this review we will use Microsoft Enterprise Library 3.1 - May 2007 and Log4Net 1.2.10. The four areas we will compare them on are easy of use, configuration, performance, flexibility.

Easy of Use

Setup of Enterprise Logging for flat files and the event log is very easy with the help of the Enterprise Library Configuration utility. Logging to the database was a little more difficult and a little awkward. For instance you need to set the Formatter for the Database Trace Listener even though it doesn't dictate what is entered into the database.

Log4Net doesn't have a UI configuration, but I've always found the setup is documented well and intuitive to implement.

Configuration

The Enterprise Logging application block can be configured using the Enterprise Library Configuration utility. Both Log4Net and Enterprise Logging modify the XML config file, so manual configuration can be done easily. Both of them also support programmatic configuration as well.

Both loggers include logging to text files, databases, event log and email. Log4Net includes logging to the console with colored ANSI for enhanced readability.

Performance

My initial tests showed Log4Net being exponentially faster. Others have found this to be true as well. For more details and stats check out Loren Halvorson's Blog.

Flexibility

The Enterprise Logging provides full source code. And has an extensible trace listeners. Log4Net's Appenders offer similar functionality.

In summary the Enterprise Logging Application Block is a very full featured and extensible logging framework. If you are using any of the other Enterprise Application Blocks this would be the first logger to try. It's only downfall is that it's performance is lacking. Unlike Log4Net the Enterprise Library including the Logging Application Block is being updated quite regularly.

If you would like to try one of these logging frameworks out check out these tutorials:
Some other Logging Frameworks:

Save to del.icio.us Add to Technorati Add to dzone

2 comments:

Rajat Nair said...

Hi jamin,
i was looking at implementing either log4net or enterprise library 3.1 on one of my projects(logging purpose only).. & finding it tough to choose between them... can you help me decide as you have been using log4net before. I would be using it for exception logging on a multi-tier application so performance is key.

My initial tests showed Log4Net being exponentially faster. - i would be interested in knowing how you have benchmarked this & reached your conclusion. (Hope its not based on Loren Halvorson's blog from 2005 which was based on enterprise library 1.0 :P )

Looking forward to your reply.

TIA

Jamin Roth said...

I came to the conclusion that Log4Net was faster based on two observations. First I wrote a simple logging app using each logging frameworks. I measured, although informally, each app in CPU consumption and output. I only tested output to a file. I also examined the path in which each logging statement traveled through each framework. Enterprise Logging uses reflection and the path is quite long. In comparison Log4Net is fairly simple and strait forward.

I've used Log4net on a few projects so I'm partial to Log4Net. Although I did validate my performance findings with some other colleagues that have used both there is still more to explore. If you are truly concerned with performance and that is the weighing factor between these two frameworks I would setup a simple app to use each. It's quick to setup and you can focus on the use cases you will need for your project's requirements.