简体   繁体   English

使用log4net记录错误/异常

[英]Logging errors/exceptions with log4net

I'm trying to log all exceptions to a sql server database through log4net, and I've seen some posts here explaining how to properly configure the web.config file, but my question is: do it is enough to get the exception logged (the application will log automatically, but in this case it does not work on my app), or do I have to call the logger from code-behind into try/catch statement? 我正在尝试通过log4net将所有异常记录到sql服务器数据库中,并且我在这里看到了一些帖子,解释了如何正确配置web.config文件,但是我的问题是:这样做是否足以记录异常(应用程序将自动记录日志,但在这种情况下无法在我的应用程序上运行),还是我必须从代​​码隐藏调用try / catch语句的记录器?

Any suggestion would be appreciated! 任何建议,将不胜感激!

Thanks a lot, Epros 非常感谢Epros

You can user Application_Error in global.asax. 您可以在global.asax中使用Application_Error。 This is called when an unhandler error occurs. 发生未处理错误时,将调用此方法。

可能会有所帮助。

没有什么可以自动捕获的,您需要连接未处理的异常以进行日志记录(以与连接任何其他全局异常管理相同的方式)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM