ASP.Net/Development/Diagnose Error
Diagnose error Demo
<source lang="csharp">
<%@ 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 & "
") 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()
%>
</source>
Page level error
<source lang="csharp">
<script language="VB" runat="server">
Sub PageLevelErrorTest() Dim intCounter as integer intCounter =1 For intCounter=1 To 10 intCounter = intCounter+1 Next Response.Write ("The value of the counter is:" & intCounter & "
") intCounter = "Storing a string to an integer" End Sub Sub Page_Error(sender As Object, exc As EventArgs) Response.Write("Error occurred: " & Server.GetLastError().ToString()) Server.ClearError() End Sub Sub Page_Load() PageLevelErrorTest() End Sub
</script>
</source>