Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • cosmin 2 posts 96 karma points
    Jan 25, 2019 @ 16:14
    cosmin
    1

    How to catch all unhandled exceptions?

    Hi, is it possible to catch all exceptions in one place, so I can log them? Thank you!

  • David Challener 80 posts 444 karma points c-trib
    Jan 25, 2019 @ 21:47
    David Challener
    0

    Hi Cosmin,

    This is quite an open ended question - there are ways to handle different types of exceptions but it really depends what you want to do and what you're doing.

    This page has some details on how to be notified of exceptions from either controllers or from an ApiController. They won't always let you catch the exception but have a read.

    https://stackify.com/csharp-catch-all-exceptions/

    Cheers,

    David

  • cosmin 2 posts 96 karma points
    Jan 28, 2019 @ 09:19
    cosmin
    103

    Thanks for your reply, David.

    In the end I found a post on this forum which had a working solution:

    https://our.umbraco.com/forum/developers/extending-umbraco/53344-Application_Error-and-Globalasaxcs#comment-201419

    Global.asax markup:

    <%@ Application Codebehind="Global.asax.cs" Inherits="YourNS.CustomGlobal" Language="C#" %>
    

    Global.asax codebehind:

    namespace YourNS
    {
        public class CustomGlobal : UmbracoApplication
        {
            protected override void OnApplicationError(object sender, EventArgs e)
            {
                var error = HttpContext.Current.Server.GetLastError();
                // Error logging code goes here...
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft