Model view controller elmah和mvc正在记录两次日志
每次Elmah记录错误时,错误都会记录两次。100%完全相同,时间戳完全相同。 我在web.config中没有特殊配置。 我创建了ElmaHandleErrorAttribute,并添加了两个过滤器:Model view controller elmah和mvc正在记录两次日志,model-view-controller,elmah,Model View Controller,Elmah,每次Elmah记录错误时,错误都会记录两次。100%完全相同,时间戳完全相同。 我在web.config中没有特殊配置。 我创建了ElmaHandleErrorAttribute,并添加了两个过滤器: filters.Add(new ElmahHandleErrorAttribute { ExceptionType = typeof(System.Data.Common.DbException), // DbError.cshtml is a v
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>
我搜索了很多,但没有一个解决方案适合我的问题。web.config或类似内容中没有双重条目
这没什么大问题,但很烦人
提前thx
©a-x-i我的设置也有同样的问题,所以我制作了一个例外日志类。然后向其添加一个静态字段,以保留记录的异常列表。然后,当OneException事件出现时,它会检查上次记录的异常,以避免重复记录
public class ExceptionLogger
{
public static List<Exception> loggedExceptions = new List<Exception>();
public static void LogException(Exception e) {
您没有在自定义ElmaHandleErrorAttribute中检查ExceptionType。因此,它将被调用2次。因为DbException是从异常继承而来的。请参阅我对这个类似问题的建议答案,直到您在不同的请求上同时抛出两个异常为止。
public override void OnException(ExceptionContext context) {
base.OnException(context);
if (!context.ExceptionHandled
|| TryRaiseErrorSignal(context)
|| IsFiltered(context))
return;
LogException(context);
}
public class ExceptionLogger
{
public static List<Exception> loggedExceptions = new List<Exception>();
public static void LogException(Exception e) {
public override void OnException(ExceptionContext context)
{
base.OnException(context);
var e = context.Exception;
if (!e.Equals(ExceptionLogger.loggedExceptions.Last()))
{
ExceptionLogger.LogException(e);
}
}