views:

8856

answers:

21

There are many Logging frameworks for .NET, from simple Debug.WriteLine and Trace to Log4Net, Logging application block, NLOg and others. Which one do you use or recommend, and why? Also, which one would you recommend to NOT use, and why?

+11  A: 

log4net, Although I've never really felt the need to use anything else...

Omar Kooheji
-1 for the subjective factorErr, I'm not respected enough to -1
nomad311
+4  A: 

See this question.

Log4Net is terrific. Very efficient, simple, configurable. Personally, I log to rolling appender files.

Geoff
A: 

log4net,

It's easy to use, and you have different appenders for different situations, and you can easily switch between appenders and assign different namespaces/classes different appenders.

hokkaido
+2  A: 

Microsoft Enterprise Library Logging Application Block is also an option. Although you would definitely want to use log4net for these reasons.

+3  A: 

I'll be the lone dissenter. I'm a big fan of Enterprise Library, even though it is quite a PITA to get initially set up.

Truthfully, what I'm a fan of, or what the next guy's a fan of, it probably doesn't matter to other devs. What does matter is how quickly you can adapt to the logging framework you choose. There's nothing wrong with log4net, nor really with EntLib, but you need to adjust to it and be able to configure and use it as needed.

John Rudy
+1 for being the lone dissenter!
Walter
Rather+1 for the objective factor
nomad311
+1  A: 

I use log4net, mainly because some major components I use also use them (NHibernate, to name one). That way I don't have to include multiple logging frameworks in my applications, and I can keep configuration in one file.

Erik van Brakel
+3  A: 

I used the built in logging in .NET using TraceSources, TraceSwitches. TraceListeners. It is easy to configure/override in the config file.

CSharpAtl
A: 

Before using any loggers it is necessary to keep it mind how the application will be accessed by clients. If you are logging into a single file, keep in mind the sharing issue under multiple processess access. For eg. if the logger is used in a web service, make sure you test the logger under heavy load.

I have used Log4net, but it is not foolproof against unexpected filelocks.

pradeeptp
Unexpected file locks are a hard to solve problem. You can let the logger wait till the file is unlocked again, but this would make the application hold for a long time. When doing logging asynchronously this could lead to missing logs when the application is terminated before the file is unlocked. With CuttingEdge.Logging I decided to immediately close the file after writing and have a fallback mechanism that allows logging to another source when logging to the file (or any logger whatsoever) fails.
Steven
+3  A: 

I have been happy with Log4Net for some time. HOWEVER I found bugs in the RollingFileAppender that cause some kind of a deadlock which hangs the IIS ( / webserver -not just IIS but Casinni also ) worker process.

Found the description of the bug. There was no recent release since 2006 so it's kind of "dead" to me...

Therefore right now I need another logging framework. I am looking at the following options :

  • Build my own (not really a pragmatic choice)
  • EntLib (Enterprise Library Logging Block)
  • NLog (just as dead as Log4Net - 2006 last release)
  • .NET Logging Framework

I am still undecided and I will have to think this thoroughly...

Andrei Rinea
After pondering the above possibilities I've decided to write my own logging library simillar to the Log4Net one but hopefully without internal deadlocks :P
Andrei Rinea
NLog is looks active. Has git repository and new releases http://nlog-project.org/
david valentine
+3  A: 

Try The Object Guy's Logging Framework. You won't be sorry.

+3  A: 

The Object Guy's Logging Framework is very simple and easy to start with. There is one small glitch to it though, because it doesn't code to Interfaces (There is no IAmLogger interface) you may have to add your own interface to it if in use with IoC, Unit Testing and other practices.

Tomas Pajonk
+5  A: 

Here's another vote for The Object Guy's Logging Framework. We've been using it for years in all our production apps. Also, it doesn't have the file-locking problem that log4net has.

S. Mills
+1  A: 

For those who are using log4net, I've made a simple console to display and filter the logs by configuring receivers (the same way you configure appenders).

I mainly use it with the .NET Remoting appender/receiver, both localy and remotely ; a lot of users are using it with the UDP appender/receiver also.

It's an open source tool developed in .NET, available on CodePlex: http://log2console.codeplex.com/

Statyk7
A: 

log4net, two reasons: interface based logging, ie: private static log4net.ILog Log = log4net.LogManager.GetLogger(typeof(thisobjectclassname))

and because you can check for Log levels before building expensive strings:

if(Log.IsDebugEnabled) Log.DebugFormat("heres my input parameters: {0}, {1}, {2}", parameter1,parameter2,parameter3);

the ObjectGuy's logger doesnt give you that, so you end up building lots of debug level strings but never using them when running in non-debug level modes! wastes efficiency.

And log4net has a wide variety of loggers: some people here point out problems with log4net and file locking, so use a database via log4net AdoNetAppender. or log to a syslog server via SysLogAppender. I didnt see either of these in ObjectGuy's logger.

enorl76
A: 

have a look: http://www.matthiasgruber.com/joomla/index.php/research (http://www.matthiasgruber.com/pdf/MatthiasToolbox.Logging.pdf) this is written for .NET 4.0 and needs no configuration at all.

Matthias
A: 

I was frustrated at the deadlocks and giant configuration files of most logging frameworks so I wrote my own as well:

http://www.kellermansoftware.com/p-14-net-logging-library.aspx

Greg Finzer
A: 

Check out Annex Logs. http://tritonsoftware.net/Products.aspx . Works with .Net 4.0 and also needs no configuration. Logs are XML based and each entry has diag info with it automatically.

Chris
+2  A: 

I think the best commercial logging framework is Gurock SmartInspect http://www.gurock.com/smartinspect/ Very flexible, high performance, customizable, awesome UI. Can be configured to log locally, via TCP, named pipes. Beats log4net IMHO.

A: 

Let me plug my own logging framework here: CuttingEdge.Logging.

CuttingEdge.Logging is a configurable logging system and can even be plugged into ASP.NET applications without a republish or recompile. The library is written in C# .NET 3.5 in Visual Studio 2008, but the library can also be used by .NET 2.0 applications. It can be used for several types of .NET applications, such as server and desktop applications. However, Compact Edition and Silverlight are not supported.

Steven
+1  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 can work with log4net and other logging frameworks. Unlike log4net, Gibraltar also gets the logs to your team from all the computers your application funs 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