如何在事件日志中获取更具描述性的错误消息?

发布于 2024-07-25 21:55:50 字数 1603 浏览 5 评论 0原文

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

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

Sub Application_Error(ByVal 发送者作为对象,ByVal e 作为 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在圣地亚哥

I am pretty new to logging. I get this jibberish in my event log.
The description for Event ID ( 0 ) in Source ( xyAMP ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: SOURCE: System.Web

How can I make this more helpful when diagnosing errors.
Here is my logging code.

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

Any suggestions to clean this up?

Thanks,
~ck in San Diego

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗藏城府 2024-08-01 21:55:50

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

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

而且,顺便说一句,当您使用这么多字符串时,您确实应该使用 StringBuilder 类进行字符串连接。 效率要高得多。

You need to use ex.ToString() to get the complete exception, along with all inner exception instances. This will tell you all that the exception wants you to know, in general.

The only other thing you can do is to write code to display the details of each exception that has such details. For instance, the WebException class has a Response property that will give you all the information about the response, and a Status property which will give you an idea of whether the Response will be useful. The SqlException has a lot of detail, including a list of all errors generated by your query. You can write special-case code that will translate these details into text.

And, BTW, you should really be using the StringBuilder class for string concatenations when you're using so many. It's much more efficient.

流年里的时光 2024-08-01 21:55:50

我认为您需要使用 消息编译器 (MC.exe )

I think you need to use the Message Compiler (MC.exe).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文