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条回答
Anthone
2楼-- · 2019-02-02 01:27

Not a direct answer, but one thing we've found useful for logging problems with our own code was creating a base exception class (inherited from Exception) and automatically logging the exception details, using Log4Net (or whatever), in all of the derived exceptions.

Obviously this won't log other types of exceptions (BCL, 3rd party) but it is useful.

The other thing about logging exceptions, if you want the full stack trace, use Exception.ToString() rather than just Exception.Message.

查看更多
登录 后发表回答