【发布时间】:2012-11-28 17:26:20
【问题描述】:
每次 Elmah 记录错误时,该错误都会记录两次。 100% 与完全相同的时间戳相同。 我在 web.config 中没有特殊配置。 我创建了一个 ElmahHandleErrorAttribute 并添加了两个过滤器:
filters.Add(new ElmahHandleErrorAttribute {
ExceptionType = typeof(System.Data.Common.DbException),
// DbError.cshtml is a view in the Shared folder.
View = "DbError",
Order = 2
});
filters.Add(new ElmahHandleErrorAttribute {
ExceptionType = typeof(Exception),
// DbError.cshtml is a view in the Shared folder.
View = "Error",
Order = 3
});
来自 web.config 的一些片段:
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
和
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
在 ElmaHandleErrorAttribute 中这段代码:
public override void OnException(ExceptionContext context) {
base.OnException(context);
if (!context.ExceptionHandled
|| TryRaiseErrorSignal(context)
|| IsFiltered(context))
return;
LogException(context);
}
我搜索了很多,但没有适合我的问题的解决方案。 web.config 中没有重复条目或类似的内容。
问题不大,但很烦人。
提前谢谢
©a-x-i
【问题讨论】:
-
您没有在自定义 ElmaHandleErrorAttribute 中检查 ExceptionType。所以它会被调用2次。因为 DbException 继承自 Exception。
-
请参阅我对这个类似问题的建议答案stackoverflow.com/a/16794746/589827
标签: model-view-controller elmah