Chat Support
Loupe - Log - Monitor - Resolve
In This Topic
    Developer's Guide for ASP.NET - Exception Handling - Creating your own Custom Exception Handling
    In This Topic

    Performing your Own Unhandled Exception Handling

    By default, the Loupe Agent will record unhandled exceptions before the AppDomain exits.  As long as the Loupe Agent for ASP.NET is configured as an ASP.NET Health Provider (which is done automatically by the Configuration Wizard) it will also record unhandled page processing exceptions.  If you create your own thread, or send requests to the .NET ThreadPool, be sure to have your own try/catch block surrounding all of the code in the thread delegate method.  If not, any exception that you don't catch will become a .NET unhandled exception and cause the application domain to rapidly shut down.  Loupe will still record details about the exception, but nothing can prevent the application domain from terminating which will cause an interruption in your web application.

    Top level exception handling in a thread main delegate
    Copy Code
    using Gibraltar.Agent;
    
    public void BackgroundThreadTask()
    {
       try
       {
          //Do your work here, it will be safe.
       }
       catch(Exception ex)
       {
          //this is the simplest method to record exceptions with the correct call attribution
          Log.RecordException(ex, "Web Site.Exceptions", true);
       }
    }
    

    The RecordException method is primarily intended for situations where you want to record the information in the log.  The advantage of the RecordException method over other logging methods (like TraceError or Log.Error) is that the log statement will be attributed to the source code location where it was thrown, making it much easier to understand where the error was generated.

    Submitting Session Data after an Exception

    You can request that the Loupe Agent automatically submit session data after an error by setting the SendSessionsOnExit property to true.  If it isn't possible to send sessions (either because of the current application configuration or the Loupe Packager isn't available) then the option will safely go back to false. 

    Automatic log data submission on exit requires spawning the Loupe Packager as a separate process.  This may not be allowed for web sites running under restricted user accounts and trust levels.  The agent will handle this condition safely.
    See Also