如何关闭 Elmah 自动日志记录?
我想在Elmah中禁用自动登录记录,在启用手动记录时,例如,
ErrorSignal.FromCurrentContext.Raise(ex)
我的情况几乎与这是一个,唯一的区别是我使用XML记录而不是SQL。我还为我用于跟踪目的的例外生成了一个唯一的ID。
当我禁用errorlog
web.config
中的模块时,如 ,我也失去了手动记录例外的能力。那时什么都没有记录。
这是global.asax
的代码:
Sub Application_Error(Sender As Object, e As EventArgs)
Dim sCode As String
sCode = Utils.NewId(IdModes.AlphaNumeric)
Try
Throw New LinkedException(sCode, Me.Server.GetLastError)
Catch ex As LinkedException
ErrorSignal.FromCurrentContext.Raise(ex)
Finally
Me.Server.ClearError()
End Try
Me.Context.Redirect($"~/oops/{sCode}")
End Sub
...这是linkedexception
:
Imports System.Web
Public Class LinkedException
Inherits HttpException
Public Sub New(ExceptionCode As String, ex As HttpException)
MyBase.New(ex.ErrorCode, $"[{ExceptionCode}] {ex.Message}", ex)
End Sub
End Class
是否可以关闭自动记录,但请保留手册?当我自动打开时,我会收到两个条目,当我关闭它时,我一无所获。
I'd like to disable automatic exception logging in Elmah, while leaving manual logging enabled, e.g.
ErrorSignal.FromCurrentContext.Raise(ex)
My situation is nearly identical to this one, with the sole difference being that I'm using XML logging instead of SQL. I'm also generating a unique ID for the exception that I'm using for tracking purposes.
When I disable the ErrorLog
module in Web.config
, however, as suggested in the answer, I also lose the ability to manually log the exception. Nothing gets logged at that point.
Here's the code from Global.asax
:
Sub Application_Error(Sender As Object, e As EventArgs)
Dim sCode As String
sCode = Utils.NewId(IdModes.AlphaNumeric)
Try
Throw New LinkedException(sCode, Me.Server.GetLastError)
Catch ex As LinkedException
ErrorSignal.FromCurrentContext.Raise(ex)
Finally
Me.Server.ClearError()
End Try
Me.Context.Redirect(quot;~/oops/{sCode}")
End Sub
...and here's LinkedException
:
Imports System.Web
Public Class LinkedException
Inherits HttpException
Public Sub New(ExceptionCode As String, ex As HttpException)
MyBase.New(ex.ErrorCode, quot;[{ExceptionCode}] {ex.Message}", ex)
End Sub
End Class
Is it possible to turn off automatic logging but leave manual turned on? When I turn on automatic I get two entries, when I turn it off I get none.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,最好让 ELMAH 完成繁重的工作,根本不使用
Application_Error
。As it turns out, it's best to let ELMAH do the heavy lifting and not use
Application_Error
at all.