是否可以使用ELMAH执行以下操作?logger.Log(" something");我正在做这样的事情:try { // Code that might throw an exception }catch(Exception ex){ // I need to log error here...}因为已处理此异常,所以ELMAH不会自动记录该异常。
3 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
直接日志写入方法,自ELMAH 1.0开始有效:
try
{
some code
}
catch(Exception ex)
{
Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex));
}
ELMAH 1.2引入了更灵活的API:
try
{
some code
}
catch(Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
两种解决方案之间有区别:
Raise方法将ELMAH过滤规则应用于异常。Log方法没有。
Raise 基于订阅,并且能够将一个异常记录到多个记录器中。
烙印99
TA贡献1829条经验 获得超13个赞
您可以使用Elmah.ErrorSignal()方法记录问题,而不会引发异常。
try
{
// Some code
}
catch(Exception ex)
{
// Log error
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
// Continue
}
- 3 回答
- 0 关注
- 425 浏览
添加回答
举报
0/150
提交
取消