Using log4net and where to implement it and using with elmah?

蹲街弑〆低调 提交于 2019-11-30 08:32:16

They're used for two different purposes.

Elmah is used to catch and store the exceptions that you did not expect. It also provides 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 knew could happen (otherwise you would not have a try / catch block).

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

To answer your specific question, 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 is also possible, but will require some custom coding which you don't want to do.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!