自动记录Try-Catch错误的方法

时间:2022-10-28 13:27:16

I have a class that send my exception to the database, and save the Error. but I have to put it inside each try {} catch{..my method here..}, and that because I have a Error log, Its a big application, and I would like to override the catch, that every time the application enter to a catch, it execute my method and send the exception and the stack-trace to the database.

我有一个类将数据发送到数据库,并保存错误。但我必须把它放在每个try {} catch {..我的方法这里..},因为我有一个错误日志,它是一个很大的应用程序,我想覆盖catch,每次应用程序进入catch,它执行我的方法并将异常和堆栈跟踪发送到数据库。

Sorry is my English is not good.

对不起,我的英语不好。

PD. I develop using MVC.NET 4 Razor

PD。我开发使用MVC.NET 4 Razor

1 个解决方案

#1


2  

You could try looking into using ELMAH (available here), which describes how to integrate this with an MVC project.

您可以尝试使用ELMAH(此处可用),它描述了如何将其与MVC项目集成。

Alternatively you could also use log4net, but this would have to be called from within your catch statement.

或者你也可以使用log4net,但必须在你的catch语句中调用它。

#1


2  

You could try looking into using ELMAH (available here), which describes how to integrate this with an MVC project.

您可以尝试使用ELMAH(此处可用),它描述了如何将其与MVC项目集成。

Alternatively you could also use log4net, but this would have to be called from within your catch statement.

或者你也可以使用log4net,但必须在你的catch语句中调用它。