Copied to clipboard

Flag this post as spam?

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


  • Nagarjun 43 posts 75 karma points
    Feb 16, 2021 @ 07:48
    Nagarjun
    0

    Logging from surface controller.

    Hi Can anyone let me know the best way to perform logging exception in Umbraco 8 from surface controller. I tried below code and it is throwing an exception "Object reference not set to an instance of an object."

    using Umbraco.Core.Logging;
    
    Logger.Error<ErrorController>("Unable to locate url :: {url}", Request.UrlReferrer.AbsolutePath);
    
  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Feb 16, 2021 @ 07:58
    Søren Kottal
    100

    Hi Nagarjun

    It is probably your Request.UrlReferrer that is null, so try checking for null on that first.

    if (Request.UrlReferrer != null) {
        Logger.Error<ErrorController>("Unable to locate url :: {url}", Request.UrlReferrer.AbsolutePath);
    }
    
  • Nagarjun 43 posts 75 karma points
    Feb 17, 2021 @ 03:16
    Nagarjun
    0

    thanks Soren. it worked.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies