M
MattB
I'm writing some code to log errors in a web app (vb/asp.net). I found a
straightforward-looking example here:
http://www.c-sharpcorner.com/Code/2002/May/CustomErrorHandlingASPNEt.asp
But mine doesn't seem to be working.
If I step through the code I put in global.asax.vb it seems to get to
the line where it checks for the existence of the log and then returns
without writing anything to the event log. I don;t know why or how to
troubleshoot it. Any suggestions? Here's the code I'm using:
----------------
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim ErrorDescription As String = Server.GetLastError.ToString
'Creation of event log if it does not exist
Dim EventLogName As String = "Test"
If (Not EventLog.SourceExists(EventLogName)) Then ' <--
stepping through code seems to end here
EventLog.CreateEventSource(EventLogName, EventLogName)
End If
' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)
End Sub
straightforward-looking example here:
http://www.c-sharpcorner.com/Code/2002/May/CustomErrorHandlingASPNEt.asp
But mine doesn't seem to be working.
If I step through the code I put in global.asax.vb it seems to get to
the line where it checks for the existence of the log and then returns
without writing anything to the event log. I don;t know why or how to
troubleshoot it. Any suggestions? Here's the code I'm using:
----------------
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim ErrorDescription As String = Server.GetLastError.ToString
'Creation of event log if it does not exist
Dim EventLogName As String = "Test"
If (Not EventLog.SourceExists(EventLogName)) Then ' <--
stepping through code seems to end here
EventLog.CreateEventSource(EventLogName, EventLogName)
End If
' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)
End Sub