views:

2083

answers:

14

What is your preferred logging infrastructure for .Net - NLog, log4net, other? Please, specify why you would use one vs. another (pros and cons).

Edit: I find it really difficult to "accept" an answer, as there is no enough data to compare. I.e. favoring one of the possibilities, w/o specifying features, that others lack, or are better implemented i more like answering the question about the best text editor. My teacher in the past told me - this is the one you know better.

Please, add more suggestions, or edit (if you have karma) other's posts. Or create a summary from the existing posts (if you can't edit). Thanks

+3  A: 

The base class library has logging facilities. System.Diagnostics.TraceSource is the principal class for this. I've mostly used the BCL as it doesn't require any 3rd party libraries and it's good enough for my purposes.

hwiechers
+12  A: 

We love log4net. It's configurable easily in code or config files. It's fast and doesn't consume a lot of memory. It has a ridiculous amount of appenders available for logging to files, the event log, email, databases (many different flavors), the console, etc. It's a pretty mature product now, too.

Bob King
+2  A: 

Log4Net. It is easy to get setup, highly configurable, and highly customizable. It is mature. It can log to console, text file, database, web service, and anything else through its extensible adapter pattern. And you can log to all of these at once, or choose what gets logged to based on error level. It can be configured through a .config file, or in code. I will never write a logger again after using log4net.

Jason Jackson
+4  A: 

I'm using SmartInspect for logging purposes. With Version 3 there is a small server application included to collect logfiles on a central server. Some preffered features are monitoring variables and the simple integration with just 1-2 lines of code.

Anheledir
+12  A: 

log4net is great, and most importantly, it's very mature. You don't want a logging system that has its own bugs. It's based off log4j, which has been around for a while.

That said, the best thing to do it pick one and roll with it. NLog and log4net are both very good, so just pick your horse and stay the course.

Ed Schwehm
A: 

I'd go with Log4Net as well.

Having said that, we've just started using the Microsoft.Practices.EnterpriseLibrary.Logging stuff. I haven't decided whether it's better or not yet...

+6  A: 

NLog - works a treat, flexible in terms of logging targets & log level thresholds and has a negligable impact on performance due to its asynchronous logging capabilities... all in all, just what the doctor ordered.

+2  A: 

What I've done is created a thin abstraction layer with its own logging API using a provider-model design pattern, which I currently use with a Log4Net provider.

The API exposed by the abstraction layer is very similar to the log4net api.

This means I can switch to another logging provider (System.Diagnostics.Trace, EntLib or other) without changing my application. Particularly important for an ISV selling enterprise software, as you may want to use the logging framework your customer is most familiar with.

Joe
+4  A: 

I am using log4net in an enterprise app. Log viewing for support is done using log4net dashboard. I have used nlog before as well. log4net is however more standard.

There is also the common logging api from spring framework that abstracts the logging library itself. http://www.springframework.net/doc-1.1-M2/reference/html/logging.html

Pratik
The latest CommonLogging version can be found herehttp://netcommon.sourceforge.net/ and the documentation here: http://netcommon.sourceforge.net/docs/2.0.0/reference/html/index.html
tobsen
+5  A: 

For ASP.NET applications, not much beats the ease of use and setup of ELMAH. Provides a full error reporting website and automatic exception logging. Sweet.

Will
A: 

I like log4net - it has good performance and is very flexible for more recently I've been using the logging in the MS Patterns and Practices Enterprise Libray 3.1 and 4.0 - the main reason being is the integration with the exception handling block and the policy injection - which brings with it elements of aspect orientated programming - I can add a LogCallHandlerAttribute to a method and have the entry and exit to the method automatically logged complete with the parameter values without writing a single line of code - add to this the other call handlers for exception handling and validation (from the validation block ) and you get a great productivity boost. the downside is that the entlib can be a pain to configure with

Richard
+1  A: 

Selecting a logging framework isn't straight forward if you develop libraries rather than applications, or when your library is intended for use across different apps. The Logging framework should be decided by the app developer and not dictated by the lib developer.

The logging framework abstraction SpringTail I use can be found on codeplex. Depending on the app or the customer's preference it will foward log calls onto a specific framework such as NLog or maybe just to Console.Out.

+1  A: 

I've found the Logging Application Block in the Enterprise Library to work well.

http://www.codeplex.com/entlib

Gordon Carpenter-Thompson
A: 

Try GIBRALTAR. Not only does it provide a non-blocking, threadsafe logging framework, it also includes a web service to collect logs and an analysis tool with extensive filtering and graphing capabilities.

GIBRALTAR combines benefits of ELMAH, Log4Net and Perfmon and takes it to the next level.

Like ELMAH, Gibraltar reports errors and supports email notifications. Unlike ELMAH which only supports ASP.NET, Gibraltar works with any .NET application (services, WinForms, WPF, etc). It also includes all the events leading up to each error and can directly integrate with multiple defect tracking systems.

Like Log4Net, Gibraltar provides trace logging. In fact, Gibraltar works with Log4Net and other logging frameworks. Unlike Log4Net, Gibraltar also gets the logs to your team from all the computers your application runs on and provides tools to analyze all that data.

Like Perfmon, Gibraltar collects and graphs Windows Performance Counters. Unlike Perfmon, Gibraltar collects key metrics continuously in a compressed format and makes it easy to track application-specific metrics. In fact, you can log all calls to key methods including parameters and return values by simply tagging those methods with an attribute.

Gibraltar offers a free 30-day trial and deep discounts for multi-user license bundles. It's not free, but it is actively supported by a passionate, experienced team that really knows and cares about logging and application monitoring. Chat with us if you have questions.

Jay Cincotta