Exception handling

Discussion in 'ASP .Net' started by tshad, Feb 6, 2006.

  1. tshad

    tshad Guest

    I am trying to set up an exception logging and have some code from a book I
    am using.

    It all seems to work except for the ID I am setting up for handling
    Exception Chains (I am only getting one entry per error - so I don't know if
    the Chain is even working).

    I have a field in my database as:

    ChainID uniqueidentifier.

    What I am putting here is a GUID.

    But all the entries show the field as blank (empty)

    I am doing a Guid.NewGuid):

    Dim chainID As Guid = Guid.NewGuid()

    So I assume I am getting an ID and putting it in the Object, which is
    putting it in the file:

    exLog.ChainID = chainID

    Why is this?

    ****************************************************************************
    Public Shared Sub Log(ByVal ex As Exception)

    Dim exLog As New ExceptionLog
    Dim parentID As Integer = 0
    Dim chainID As Guid = Guid.NewGuid()
    Dim dbConn As SqlConnection = New
    SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsolutions"))

    dbConn.Open()

    'Iterate through all of the exceptions in the exception chain
    While Not ex Is Nothing

    'Create a new Exception Log object for the exception
    exLog = New ExceptionLog()

    'Acquire the user name
    If Current.User.Identity.IsAuthenticated Then
    exLog.UserID = Current.User.Identity.Name
    Else
    exLog.UserID = "<Anonymous User>"
    End If

    exLog.ParentID = parentID
    exLog.MachineName = Current.Server.MachineName
    exLog.UserAgent = Current.Request.UserAgent
    exLog.ExceptionDate = Now
    exLog.ExceptionType = ex.GetType.ToString
    exLog.ExceptionMessage = ex.Message
    ' exLog.Page =
    Current.Request.AppRelativeCurrentExecutionFilePath()
    exLog.StackTrace = ex.StackTrace
    exLog.QueryStringData = GetQuerystringData()
    exLog.FormData = GetFormData()
    exLog.ChainID = chainID

    'Save Exception Log, Get New ParentID, Get Next Inner Exception
    If exLog.Save(dbConn) Then
    parentID = exLog.ExceptionID
    ex = ex.InnerException
    Else
    ex = Nothing
    End If

    End While

    dbConn.Close()

    End Sub
    ****************************************************************************

    Thanks,

    Tom
    tshad, Feb 6, 2006
    #1
    1. Advertising

  2. tshad

    tshad Guest

    I found that the blank GUID was actually only showing that way if you did a
    Return All Rows from Enterprise manager. A "Select * ..." actually works
    fine.

    I still don't know why I am not getting any chains. I always get only one.

    I am doing:

    While Not ex Is Nothing

    'Create a new Exception Log object for the exception
    exLog = New ExceptionLog()
    ex = ex.InnerException

    End While

    But it always only does one exception - no chain.

    Is this something only available in 2.0?

    Thanks,

    Tom

    "tshad" <> wrote in message
    news:...
    >I am trying to set up an exception logging and have some code from a book I
    >am using.
    >
    > It all seems to work except for the ID I am setting up for handling
    > Exception Chains (I am only getting one entry per error - so I don't know
    > if the Chain is even working).
    >
    > I have a field in my database as:
    >
    > ChainID uniqueidentifier.
    >
    > What I am putting here is a GUID.
    >
    > But all the entries show the field as blank (empty)
    >
    > I am doing a Guid.NewGuid):
    >
    > Dim chainID As Guid = Guid.NewGuid()
    >
    > So I assume I am getting an ID and putting it in the Object, which is
    > putting it in the file:
    >
    > exLog.ChainID = chainID
    >
    > Why is this?
    >
    > ****************************************************************************
    > Public Shared Sub Log(ByVal ex As Exception)
    >
    > Dim exLog As New ExceptionLog
    > Dim parentID As Integer = 0
    > Dim chainID As Guid = Guid.NewGuid()
    > Dim dbConn As SqlConnection = New
    > SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsolutions"))
    >
    > dbConn.Open()
    >
    > 'Iterate through all of the exceptions in the exception chain
    > While Not ex Is Nothing
    >
    > 'Create a new Exception Log object for the exception
    > exLog = New ExceptionLog()
    >
    > 'Acquire the user name
    > If Current.User.Identity.IsAuthenticated Then
    > exLog.UserID = Current.User.Identity.Name
    > Else
    > exLog.UserID = "<Anonymous User>"
    > End If
    >
    > exLog.ParentID = parentID
    > exLog.MachineName = Current.Server.MachineName
    > exLog.UserAgent = Current.Request.UserAgent
    > exLog.ExceptionDate = Now
    > exLog.ExceptionType = ex.GetType.ToString
    > exLog.ExceptionMessage = ex.Message
    > ' exLog.Page =
    > Current.Request.AppRelativeCurrentExecutionFilePath()
    > exLog.StackTrace = ex.StackTrace
    > exLog.QueryStringData = GetQuerystringData()
    > exLog.FormData = GetFormData()
    > exLog.ChainID = chainID
    >
    > 'Save Exception Log, Get New ParentID, Get Next Inner Exception
    > If exLog.Save(dbConn) Then
    > parentID = exLog.ExceptionID
    > ex = ex.InnerException
    > Else
    > ex = Nothing
    > End If
    >
    > End While
    >
    > dbConn.Close()
    >
    > End Sub
    > ****************************************************************************
    >
    > Thanks,
    >
    > Tom
    >
    >
    tshad, Feb 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Babu
    Replies:
    1
    Views:
    2,916
    Jim Gibson
    Mar 10, 2005
  2. Mark Tarver
    Replies:
    22
    Views:
    1,302
    J Kenneth King
    Apr 26, 2009
  3. Peter
    Replies:
    34
    Views:
    1,936
    James Kanze
    Oct 17, 2009
  4. VSK
    Replies:
    0
    Views:
    247
  5. Iñaki Baz Castillo
    Replies:
    1
    Views:
    187
    Iñaki Baz Castillo
    Apr 15, 2008
Loading...

Share This Page