views:

77

answers:

2

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

A: 

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

ChrisW
What's this got to do with MC?
John Saunders
A: 

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.

John Saunders