Copied to clipboard

Flag this post as spam?

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


  • Nagarjun 39 posts 71 karma points
    Mar 19, 2021 @ 09:13
    Nagarjun
    1

    logging error in global.asax

    Hi,

    Can any one let me know on how to log error in OnApplicationError in global.cs

     protected override void OnApplicationError(object sender, EventArgs evargs)
            {
                base.OnApplicationError(sender, evargs);
                var exception = Server.GetLastError();
                Umbraco.Core.Composing.Current.Logger.Error(typeof(Global), evargs.ToString());
                Umbraco.Core.Composing.Current.Logger.Error(typeof(Global), exception.ToString());
                //Server.ClearError();
    
            }
    
  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Mar 20, 2021 @ 11:24
    Huw Reddick
    1

    You need to create a class that inherits UmbracoApplicationBase, you can add your error handler to this and then change the inherits value in global.asax.

    Check this post for some info https://our.umbraco.com/forum/developers/extending-umbraco/53344-Application_Error-and-Globalasaxcs#comment-201419

  • Nagarjun 39 posts 71 karma points
    Mar 22, 2021 @ 09:08
    Nagarjun
    0

    Hi Reddik,

    My class is getting pickup and Application_error method is working. But the below line of code is not writing any log.

    Umbraco.Core.Composing.Current.Logger.Error(typeof(global), exception.ToString());
    
  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Mar 22, 2021 @ 16:05
    Huw Reddick
    0

    looking at the umbraco base code, my guess would be that the logger may not be instantiated at the point you are trying to use it,

    There is a function in the core UmbracoApplication class that instantiates the logger. Also since you are overriding OnApplication error it is quite possible that your error will occur before the application is loaded and would therefore never get logged by Umbraco.

    if you are inheriting from UmbracoApplication, you could try something like

    Current.Logger.Error<UmbracoApplicationBase>(exception, "An unhandled exception occurred");
    
Please Sign in or register to post replies

Write your reply to:

Draft