从 Elmah 错误邮件中过滤已发出信号的异常
我已经围绕 Elmah 的错误信号实现了一个包装方法,其中引发的异常只能由 Elmah 在日志记录和邮件发送中看到,但现在我只想从邮件中过滤掉这些信号异常,但仍然记录它们。我该怎么做?
这是我的简单包装器:
public void LogException(Exception exception)
{
ErrorSignal.FromContext(HttpContext.Current).Raise(exception);
}
我想过将输入异常包装在自定义 SignalledException 中,并从邮件中过滤掉这些异常,但随后我的日志充满了 SignalledException,而不是真正的异常。
还有其他想法吗?
I've implemented a wrapper method around Elmah's Error Signaling, where a raised exception is only seen by Elmah for logging and mailing, but now I'd like to filter only these signalled exceptions out of the mailing, but still log them. How can I do this?
This is my simple wrapper:
public void LogException(Exception exception)
{
ErrorSignal.FromContext(HttpContext.Current).Raise(exception);
}
I've thought of wrapping the input exception in a custom SignalledException, and filtering those out of mailing, but then my logs get full of SignalledExceptions, and not the real exceptions.
Any other ideas please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Elmah 过滤主要针对异常类型。编程过滤允许我检查添加到异常的信息,但我还没有遇到带有
ElmahFilteringData
属性的异常类型,而且我不喜欢“侵入”我想要记录的异常。以下是我如何仅针对某些已发出信号的异常发送电子邮件通知:首先,我有一个特殊的包装器异常,纯粹是为了告诉 Elmah 不要针对此类异常发送电子邮件通知:
然后,当我引发异常时,我通常只想记录并且不是通过电子邮件发送,但有时可能通过电子邮件发送,我在异常日志记录服务中使用此代码:
现在,在 Global.asax 中的 Elmah 过滤器事件中,我解开异常以记录它,如果它被包装,则从电子邮件中忽略它通知管道:
Elmah filtering works mainly on exception types. Programmatic filtering would allow me to examine information added to an exception, but I have yet to come across an Exception type with an
ElmahFilteringData
property, and I prefer not to 'invade' the exceptions I want logged. Here is how I accomplished only sending email notificatins for certain signalled exceptions:First I have a special wrapper exception, purely for telling Elmah not to send an email notification for exceptions of this type:
Then, when I raise an exception I normally only want logged and not emailed, but maybe sometimes emailed, I use this code in my exception logging service:
Now, in the Elmah filter events in Global.asax, I unwrap the exception to log it, and if it is wrapped, dismiss it from the email notification pipeline: