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
    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 712 posts 4570 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 39 posts 71 karma points
    Feb 17, 2021 @ 03:16
    Nagarjun
    0

    thanks Soren. it worked.

Please Sign in or register to post replies

Write your reply to:

Draft