Diagnose error Demo : Diagnose Error « Development « ASP.Net






Diagnose error Demo

<%@ Import Namespace="System.Diagnostics" %>
<script language="VB" runat="server" >
 Sub EntrytoLog()
     dim intCounter as integer
     intCounter =1
     for intCounter=1 to 10
      intCounter = intCounter+1
     next
     response.write ("The value of the counter is:" & intCounter & "<br>")
     intCounter = "Storing a string to an integer"
     End sub
    
     Sub Page_Error(sender As Object, exc As EventArgs)
     dim errorMessage as string
     errorMessage = "Error occurred" & Server.GetLastError().ToString()
     Server.ClearError()
     Dim LogName As String = "MyApplicationLog"
     Dim SourceName As String = "MyApplicationSource"
     If (Not EventLog.SourceExists(SourceName))
     EventLog.CreateEventSource(SourceName, LogName)
     End If
    
     'Insert into Event Log
     Dim MyLog As New EventLog
     MyLog.Source = LogName
     MyLog.WriteEntry(errorMessage, EventLogEntryType.Error)
 End Sub
</script>
<%

 EntrytoLog()
%>

           
       








Related examples in the same category

1.Page level error