views:

370

answers:

6

(subjective)

I'm looking for what your using to perform logging in your application. This log4net thing is giving me headaches. Is there a better answer out there or is everone just homebrewing a solution? I know the System.Diagnostics.Trace subsystem is quite capable should I layer on this?

+6  A: 

NLog is probably the other big player in this area. Also, There is an application bloc in entreprise library that is dedicated to tracing and logging.

Romain Verdier
+1 for NLog, had not seen it used I'll take a look.
csharptest.net
+1  A: 

Why not use just the .NET classes for logging?

With Custom-Listeners you can do almost anything for logging, can apply filters, spread your logs to multiple targets, databases, files, network, whatever.

Just watch out what the .NET-Framework is capable of, you'll be surprised.

BeowulfOF
I was considering this approach. The biggest challange is you still end up implementing all the writers for thread saftey and wrapping the client API calls to prevent string formatting ect, from crashing the application. Since most logging is done in a catch block, generating exceptions is bad mojo. Still a viable approach to use the mechanic though, but it still ends up being mostly home-brew.
csharptest.net
+2  A: 

Try Elmah its pretty easy, mind you log4net is not so bad once you get your head into it....

What actually are your headaches?

Rippo
Mostly concurency issues with a multi-instance application. That and the whole thing is fairly fault-intolerant. For instance when a logger fails other loggers aren't being called. It's also really annoying in NUnits generating error output due to file-lock collisions with the actual software. This is mostly due to the way we test webservices by running the Asp.net host in-proc without 'specializing' the web.config.
csharptest.net
@csharptest.net: Not quite sure what you mean. Log4net is fail-stop by design; see http://logging.apache.org/log4net/release/faq.html under "Is log4net a reliable logging system?". If you're relying on logging to always work, log4net is not for you.
TrueWill
+1  A: 

We use the Enterprise Library exclusively in our corporate environment (Logging Block). And I've recently started to use Log4Net on personal projects.

From experience, the Enterprise Library, albeit powerful, is a mighty pain to get up and running. Not only from just trying to figure out which dll's to use, but the configuration can become unwieldy.

On the flip side, I've found Log4Net to be extremely easy and you can be up and running in no time; quite literally in less than an hour.

Granted I'm a MS fanboy (ok, not really, but they are the reason I can make a living) and typically go with MS. However, I've made the recommendation to migrate to Log4Net at work. The simplicity of it really is refreshing.

Metro Smurf
A: 

Take a look at Common.Logging. It works with all major logging frameworks (system.diagnostics, log4net, nlog, entreprise library) and allows you to switch logging frameworks from configuration.

From my personal experience - I've used .NET tracing in a corporate environment which didn't allow us to use opensource, and after we perfected the rolling file tracelistener, it was quite easy to use. Now I use log4net and it's pretty nice, but takes some getting used to.

RA
+1  A: 

There are quite a few .NET logging libraries and tools out there, here's an extensive list:

http://www.dotnetlogging.com/

You might also want to take a look at our .NET logging product SmartInspect, which provides rich logging capabilities (in contrast to the text-only logging features of most other logging tools) and comes with a log viewer and optional log server application.

Dennis G.