是否可以使用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 關注
- 447 瀏覽
添加回答
舉報
0/150
提交
取消