Skip to main content
 首页 » 编程设计

c#之Elmah 自定义记录器不工作

2024年02月20日16pengyingh

我想要一个全局点来处理 asp.mvc3 应用程序中的所有异常。 我创建了新的应用程序,使用 nuget 添加了 elmah 并实现了 ElmahCustomLogger 类。我还在 web.config elmah 部分注册了这个自定义记录器。

出于某种原因,ElmahCustomLogger::Log 方法从未被调用(我在那里设置了一个刹车点)

public class ElmahCustomLogger : ErrorLog  
{ 
    public override string Log(Error error) 
    { 
        throw new NotImplementedException(); 
    } 
 
    public override ErrorLogEntry GetError(string id) 
    { 
        throw new NotImplementedException(); 
    } 
 
    public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList) 
    { 
        throw new NotImplementedException(); 
    } 
} 

请您参考如下方法:

看起来我只需要声明特定的构造函数即可使其工作:

public class ElmahCustomLogger : Elmah.ErrorLog 
{ 
    public ElmahCustomLogger(IDictionary config) {} 
    ... 
}