Use Global.asax to log application level exception : Exception « Development « ASP.NET Tutorial






<%@ Application Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %> 
<%@ Import Namespace="System.Text" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    {
        // Obtain the URL of the request 
        string url = Request.Path;

        // Obtain the Exception object describing the error 
        Exception error = Server.GetLastError();

        // Build the message --> [Error occurred. XXX at url]
        StringBuilder text = new StringBuilder("Error occurred. ");
        text.Append(error.Message);
        text.Append(" at ");
        text.Append(url); 

        // Write to the Event Log 
        EventLog log = new EventLog();
        log.Source = "Core35 Log";
       // log.WriteEntry(text.ToString(), EventLogEntryType.Error);
    }
</script>








9.18.Exception
9.18.1.What is going to happen if there is no exception handler
9.18.2.Divide By Zero With Exception
9.18.3.Catch exception and display exception message, Source and StackTrace (C#)
9.18.4.Page-level error handling
9.18.5.Application-level error handling
9.18.6.Try to catch error when converting text value to number
9.18.7.Use Global.asax to log application level exception
9.18.8.Generic error handler page
9.18.9.Transfer to different page based on exception type