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

时间:2023-02-03 15:05:22

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

我很擅长伐木。我在事件日志中得到了这个乱码。无法找到源(xyAMP)中事件ID(0)的描述。本地计算机可能没有必要的注册表信息或消息DLL文件来显示来自远程计算机的消息。您可以使用/ AUXSOURCE =标志来检索此描述;请参阅帮助和支持以获取详细信以下信息是事件的一部分: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

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

谢谢,〜在圣地亚哥

2 个解决方案

#1


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.

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

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.

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

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

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

#2


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

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

#1


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.

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

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.

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

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

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

#2


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

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