gpt4 book ai didi

c# - elmah 自定义提供者和公开事件

转载 作者:太空狗 更新时间:2023-10-30 00:57:23 26 4
gpt4 key购买 nike

我想知道如何创建我的自定义提供程序来存储错误日志,例如。 Windows 事件查看器的提供程序。

如果到目前为止不可能,我也想知道是否有任何公开的事件我可以覆盖,以便我可以注入(inject)我的代码,获取异常,做任何我想做的事。

我知道我可以在 Global.asax 中覆盖一些事件。比如过滤:

void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
}
void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs )
{
}

还有吗?我在哪里可以找到这些事件的列表?

最佳答案

关于创建 Elmah 事件日志提供程序,如果您打算将错误信息存储在事件日志中并同时使用 ELMAH UI,这可能不是一个好主意。 related question Matthew Daugherty 就这个话题给出了很好的回答:

ELMAH error log classes are not write-only; they also read the log data so that it can be displayed in the ELMAH web interface. Additionally, ELMAH logs more than just exception information. It also logs server variables, the form collection, and the information necessary to reproduce the yellow screen of death. Even if you were to log all of this information to the event log it would be difficult to read as plain text, and very difficult to read back in such a way that the ELMAH web interface could use it. If you are not going to use the ELMAH web interface then clearly that is not an issue.

为了创建自定义日志记录提供程序,您可以子类化 ErrorLog 并覆盖 GetError(通过 ID 获取单个错误;由 Elmah UI 使用)、GetErrors(在页面上列出所有错误;由 Elmah UI 使用)和Log(记录一个新的错误)方法来提供你自己的存储机制。参见 this article有关如何实现自定义错误日志的示例。

然后您在配置中注册新的 ErrorLog 提供程序:

<elmah> 
<errorLog type="MyNamespace.MyErrorLog, MyAssemblyName"/>
</elmah>

关于事件,它们是由 Elmah 模块发出的。在 ErrorLogModule 中有两个事件 - Logged 和 Filtering。在 ErrorMailModule 中有四个事件 - Filtering、Mailing、Mailed 和 DisposingMail。

关于c# - elmah 自定义提供者和公开事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5363088/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com