How should I log exceptions in ASP.NET?

2019-02-02 00:47发布

How should I log exceptions? I never tried logging in .NET before. Nor try to dump exceptions to a txt (or binary) file. I dont require a text file, just a way to view the logs with the file and line #.

-edit- using asp.net

13条回答
地球回转人心会变
2楼-- · 2019-02-02 01:06

Actually, since ASP.NET 2.0, you don't really have to log any exceptions. ASP.NET Health Monitoring does that for you. By default, it will log exceptions, as warnings, to the Application event log.

This process an be customized through configuration.

See ASP.NET Health Monitoring Overview.

查看更多
我命由我不由天
3楼-- · 2019-02-02 01:07

While we're plugging all sorts of logging frameworks here, let me plug CuttingEdge.Logging. It's simple to setup and integrates well with ASP.NET, but lacks a viewer such as ELMAH has.

查看更多
叼着烟拽天下
4楼-- · 2019-02-02 01:08

I agree with those that mentioned ELMAH.

The only fault with ELMAH is that it can't log exceptions that happen outside of an actual user initiated request. So if you use timers or have a lot of code running out of applicaiton_start type events you'll have to manually log those exceptions. The best part of ELMAH is that it is very easy to setup, and comes with a UI so you can actually look at the logs (why none of the other loggers seem to come with a UI is quite beyond my understanding).

Log4Net is a much more complete logging solution, and is especially good if you want to do diagnostic logging, informational logging, or otherwise want to log things that "are not errors". Easier to configure and use then Enterprise Library.

Enterprise Library's logging component is also popular, but EntLib is also about as light-weight and subtle as a freight-train, especially if you aren't using the rest of what EntLib has to offer.

查看更多
Fickle 薄情
5楼-- · 2019-02-02 01:11

NLog is pretty nice. It's easier to configure than log4net...

查看更多
放荡不羁爱自由
6楼-- · 2019-02-02 01:11

Link

  • log4net is very good option.
查看更多
地球回转人心会变
7楼-- · 2019-02-02 01:12

Log4Net is great and quick to learn. For lots of extra features and visualizations, there is Exceptioneer.

查看更多
登录 后发表回答