views:

1575

answers:

2

Hi there,

does anyone have experience with log4net, i have been looking at elmah which is great. But i wanted a little bit more control i.e. to use logging not only in asp.net but also in wpf.

Anway i decided to take a look at log4net.

I have 2 clients, (wpf and asp.net) that both share business logic.

Should i be raising events in business logic and in the client also ??

I presume the business logic will use the app.config / web.config (business logic is in another layer - a class project)

Has anybody used log4net together with elmah, is there anyway you can get them to share the same db table??

log4net seems to me the ultimate logging framework but elmah has that edge of submitting all the SERVER variables and stack trace etc

OR maybe its possible to get log4net to save the Stacktrace also and replace elmah completely??

Any comments really appreciated

+1  A: 

I've been using log4net for a while now and I primarily have my data layer and business layers do all of the logging for errors. However, if your presentation layer has a decent amount of "computing" going on with objects, it would be worthwhile to have the appropriate information logged there too.

You can configure log4net to have its settings stored in the .config file, or in its own separate configuration file. The advantage to the separate file is that if you need to switch logging modes on the fly, you can do it in the separate .config file and not have IIS trigger an application refresh of the site.

I have not used ELMAH yet, but it does look very nice. I think more importantly, it provides a way to plug into existing applications with no hassle. However, log4net does provide an easier way to get more detailed and extensive logging information since you have so many configuration options to work with.

If don't need a fine grained level of logging for your applications, I'd go with ELMAH. If you want to go for a more detailed approach, take the time to work log4net into your application.

That's my 10 bits.

Dillie-O
+8  A: 

They're used for two different purposes.

Elmah is used to catch and store the exceptions that you did not expect. It also provide a few front ends (web page, RSS, email alerter) for delivering the exceptions.

Log4net on the other hand is for logging events (including errors caused by exceptions) that you kind of new could happen (otherwise you would not have a try / catch block).

Therefore, you should use both, not one or the other.

You can get log4net to log stacktrace of exception, but you should not generally log stack trace for every debug message that you log. Logging server variables and other web-specific stuff will require some custom coding which you don't want to do.

zvolkov