是否ELMAH处理捕获的异常以及异常、ELMAH

2023-09-02 01:43:53 作者:小明不死数学难亡i

记录异常,即使他们不冒泡到应用程序?我想,当发生异常时弹出一个消息,仍然记录异常。目前,我已经把一切都在尝试catch块,并吐出的消息,但是这得乏味。

Does ELMAH logged exceptions even when they do not bubble up to the application? I'd like to pop up a message when an exception occurs and still log the exception. Currently I've been putting everything in try catch blocks and spitting out messages, but this gets tedious.

推荐答案

ELMAH已更新,以支持新的功能,称为的信令。

ELMAH has been updated to support a new feature called Signaling.

这可以让你处理,你怎么想的例外,同时还记录他们ELMAH。

This allows you to handle exceptions how you want, while still logging them to ELMAH.

try
{
    int i = 5;
    int j = 0;
    i = i / j; //Throws exception
}
catch (Exception ex)
{
    MyPersonalHandlingCode(ex);
    ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH Signaling
}

重新抛出异常可能是一个不好的做法,因为它使人们难以跟踪应用程序的流程。使用信令是一个更好的方法,如果你打算处理以某种方式错误,只是想记录它。

Re-throwing exceptions can be a bad practice as it makes it difficult to trace the flow of an application. Using Signaling is a much better approach if you intended to handle the error in some fashion and simply want to document it.

请检查出ELMAH 这个优秀的导游 DotNetSlackers

Please check out this excellent guide by DotNetSlackers on ELMAH