【问题标题】:How can I get a more descriptive error message in my event log?如何在我的事件日志中获得更具描述性的错误消息?
【发布时间】:2009-07-07 17:07:47
【问题描述】:

我对日志记录很陌生。我在我的事件日志中得到了这个乱码。 找不到源 (xyAMP) 中事件 ID (0) 的描述。本地计算机可能没有必要的注册表信息或消息 DLL 文件来显示来自远程计算机的消息。您可以使用 /AUXSOURCE= 标志来检索此描述;有关详细信息,请参阅帮助和支持。以下信息是事件的一部分:SOURCE: System.Web

在诊断错误时如何使这更有帮助。 这是我的日志记录代码。

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim ctx As HttpContext = HttpContext.Current

    Dim ex As Exception = ctx.Server.GetLastError()

    Dim data As String = String.Empty
    Dim referer As String = IIf(ctx.Request.ServerVariables("HTTP_REFERER") IsNot Nothing, ctx.Request.ServerVariables("HTTP_REFERER").ToString(), String.Empty)
    Dim sForm As String = IIf(ctx.Request.Form IsNot Nothing, ctx.Request.Form.ToString(), String.Empty)
    Dim sQuery As String = IIf(ctx.Request.QueryString IsNot Nothing, ctx.Request.QueryString.ToString(), String.Empty)

    data = "SOURCE: " + ex.Source + vbCrLf
    data += "MESSAGE: " + ex.Message + vbCrLf
    data += "FORM: " + sForm + vbCrLf
    data += "QUERYSTRING: " + sQuery + vbCrLf
    data += "TARGETSITE: " + ex.TargetSite.ToString() + vbCrLf
    data += "STACKTRACE: " + ex.StackTrace + vbCrLf
    data += "REFERRER: " + referer

    Dim eventLogName As String = "xyAMPLog"
    Dim sourceName As String = "xyAMP"

    Dim xyAMPLog As New EventLog()
    xyAMPLog.Log = eventLogName
    xyAMPLog.Source = sourceName


    Try
        xyAMPLog.WriteEntry(data, EventLogEntryType.Error)

    Catch exc As Exception
        Console.WriteLine(exc.Message)
    End Try

    'ctx.Server.ClearError()


End Sub

有什么清理的建议吗?

谢谢, ~ck 在圣地亚哥

【问题讨论】:

    标签: event-log error-logging


    【解决方案1】:

    您需要使用ex.ToString() 来获取完整的异常以及所有内部异常实例。一般来说,这将告诉您异常希望您知道的所有信息。

    您唯一能做的另一件事是编写代码来显示具有此类详细信息的每个异常的详细信息。例如,WebException 类有一个 Response 属性,可以为您提供有关响应的所有信息,还有一个 Status 属性,可以让您了解Response 是否有用。 SqlException 有很多详细信息,包括查询生成的所有错误的列表。您可以编写将这些详细信息转换为文本的特殊情况代码。

    而且,顺便说一句,当你使用这么多字符串连接时,你真的应该使用StringBuilder 类。效率更高。

    【讨论】:

      【解决方案2】:

      我认为您需要使用Message Compiler (MC.exe)

      【讨论】:

      • 这和MC有什么关系?
      • 我进入这个问题时认为这是一个 MC 问题,但它看起来更像是一个记录器问题。在这里找不到我的 MC.exe 问题的提示:P
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 2017-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多