需要确定ELMAH正在记录未处理的异常,或其中一ErrorSignal.Raise提出() [英] Need to determine if ELMAH is logging an unhandled exception or one raised by ErrorSignal.Raise()
问题描述
我是用我的Global.asax文件中ELMAH记录的事件给用户时未处理的异常发生时转移到一个反馈表。
I am using the Elmah Logged event in my Global.asax file to transfer users to a feedback form when an unhandled exception occurs.
有时候我登录其他处理的异常。例如:
Sometimes I log other handled exceptions. For example:
ErrorSignal.FromCurrentContext().Raise(new System.ApplicationException("Program code not found: " + Student.MostRecentApplication.ProgramCode));
// more code that should execute after logging this exception
我遇到的问题是,记录的事件被炒鱿鱼为未处理而这些处理,产生的异常。有没有一种方法来确定,在记录的事件处理程序,通过ErrorSignal类的异常是否提高或只是未处理?是否有其他ELMAH事件,我可以利用?
The problem I am having is that the Logged event gets fired for both unhandled and these handled, raised exceptions. Is there a way to determine, in the Logged event handler, whether the exception was raised via ErrorSignal class or was simply unhandled? Are there other Elmah events that I can take advantage of?
推荐答案
厌倦了试图找到正确的方式做到这一点,所以我结束了创建我自己的异常类型:
Tired of trying to find the "right" way to do this, so I ended up creating my own exception type:
public class HandledElmahException : Exception
{
public HandledElmahException() : base() { }
public HandledElmahException(string message) : base(message) { }
public HandledElmahException(string message, Exception innerException) : base(message, innerException) { }
}
然后,在ErrorLog.Logged事件处理我只是检查,看看是否异常的类型是 HandledElmahException
。
void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)
{
if (args.Entry.Error.Exception is HandledElmahException)
return;
// my code to transfer to custom error page to collect feedback...
}
所以,如果我不想带他们去的errorPage,当记录一个例外,我用我特殊的 HandledElmahException
类的一个实例,它可以是来自
So, if I don't want to take them to the ErrorPage, when an exception is logged, I use an instance of my special HandledElmahException
class, which can be derived from.
ErrorSignal.FromCurrentContext().Raise(new HandledElmahException("Program code not found: " + Student.MostRecentApplication.ProgramCode));
这篇关于需要确定ELMAH正在记录未处理的异常,或其中一ErrorSignal.Raise提出()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!