是否可以使用ELMAH进行以下操作?
logger.Log(" something");
我是这样做的:
try
{
// Code that might throw an exception
}
catch(Exception ex)
{
// I need to log error here...
}
ELMAH不会自动记录此异常,因为它已被处理。
是否可以使用ELMAH进行以下操作?
logger.Log(" something");
我是这样做的:
try
{
// Code that might throw an exception
}
catch(Exception ex)
{
// I need to log error here...
}
ELMAH不会自动记录此异常,因为它已被处理。
当前回答
我试图写自定义消息到elmah日志使用Signal.FromCurrentContext().Raise(ex);并发现这些例外都是冒泡的,例如:
try
{
...
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
// this will write to the log AND throw the exception
}
此外,我不知道elmah是如何支持不同级别的日志记录的——是否有可能通过web关闭详细日志记录。配置设置?
其他回答
使用这条线,它工作得非常好。
try{
//Code which may throw an error
}
catch(Exception ex){
ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex));
}
我试图写自定义消息到elmah日志使用Signal.FromCurrentContext().Raise(ex);并发现这些例外都是冒泡的,例如:
try
{
...
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
// this will write to the log AND throw the exception
}
此外,我不知道elmah是如何支持不同级别的日志记录的——是否有可能通过web关闭详细日志记录。配置设置?
我在使用ASP。NET core和ElmahCore。
要手动记录HttpContext中的错误(在控制器中),只需写:
using ElmahCore;
...
HttpContext.RiseError(new Exception("Your Exception"));
在没有HttpContext的应用程序的另一部分:
using ElmahCore;
...
ElmahExtensions.RiseError(new Exception("Your Exception"));
catch(Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
可以使用Elmah.ErrorSignal()方法记录问题而不引发异常。
try
{
// Some code
}
catch(Exception ex)
{
// Log error
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
// Continue
}