Copied to clipboard

Flag this post as spam?

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


  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 17, 2019 @ 17:01
    Heather Floyd
    0

    Use of Current.Logger in UmbracoViewPage, etc?

    So, I'm not sure if I am doing something wrong or this is a bug...

    If I have a basic Template inheriting UmbracoViewPage... why don't my log messages appear in the LogViewer?

    Here is some relevant test code:

    @using MySite.Models
    @using Umbraco.Core.Composing;
    @using Umbraco.Core.Logging;
    
    @inherits UmbracoViewPage<ArticlesListing>
    @{
        Layout =  "MasterSitePage.cshtml";
    
        //Test logging
        var page = Umbraco.AssignedContentItem.Name;
        var tempError = new Exception("Just a fake error!");
        Current.Logger.Error<UmbracoViewPage<ArticlesListing>>(tempError, "TEST ERROR in ArticlesListing on '{Page}'", page);
    }
    

    If I visit a page that uses this template, then check the LogViewer, it is showing no errors logged. Searching for the specific message doesn't turn up anything either.

    I have reviewed the current documentation at https://our.umbraco.com/documentation/getting-started/Code/Debugging/Logging/ and have looked at another forum question (also about Logging issues - but their specific question is about Custom components - https://our.umbraco.com/forum/umbraco-8/97996-bug-with-currentlogger-or-maybe-im-using-it-wrong)

    Has anyone gotten logging to work in V8? If so, what am I missing here?

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Oct 17, 2019 @ 17:14
    Anders Bjerner
    1

    Hi Heather,

    What version of Umbraco 8 are you using? I just tried your code in my 8.2 solution, and it works fine.

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 17, 2019 @ 17:22
    Heather Floyd
    0

    I've tried it in an 8.2 site and in an 8.1.5 site.

    Do you know of anything which might somehow interfere with logging in general?

    I see all the standard Umbraco-provided log messages, but nothing that I have added...

    (These are Umbraco Cloud sites - if that makes any difference.)

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Oct 17, 2019 @ 17:37
    Anders Bjerner
    0

    I don't know if Cloud does any specific. You could try reaching out to their support.

    Does it work if you remove the UmbracoViewPage part when writing to the log? As it's in the Umbraco namespace, it could be that they intercept that on Cloud.

    Btw - my solution is just a test site I set up the other day when 8.2 was released the other day, so it's pretty standard.

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 17, 2019 @ 20:24
    Heather Floyd
    0

    Thanks, Anders, I'll try your suggestions.

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 19, 2019 @ 16:54
    Heather Floyd
    0

    SO, I did a file comparison between my site and a download of 8.2 for the Releases page.

    No significant config or file differences which might indicate something having to do with Serilog...

    The only thing I can imagine is that since I have a custom controller intercepting all page requests, somehow that is interfering with logging... But I'm not quite sure how it would. or what I'd need to do about it.

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 19, 2019 @ 17:12
    Heather Floyd
    0

    As a test, I removed my custom dll which intercepts the page requests and set a breakpoint in a stripped-down template file, at the line 'Current.Logger.Error...'

    Upon running the page and hitting the breakpoint:

    Current.Logger = {Umbraco.Core.Logging.Serilog.SerilogLogger}
    

    I then DID see the log messages in the LogViewer.

    I re-added my custom dll, and checked the breakpoint again -

    Current.Logger = {Umbraco.Core.Logging.DebugDiagnosticsLogger}
    

    So, somewhere along the way, "Logger" changed type.

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 19, 2019 @ 18:34
    Heather Floyd
    1

    Okay, I've managed to fix this for my project. I don't totally understand why this fixes it, but if I add private logger variables to my custom Controllers, the Views now log correctly.

    public abstract class WebControllerBase : SurfaceController, IRenderMvcController
        {
            private readonly ILogger _logger;
    
            public WebControllerBase(ILogger logger)
            {
                _logger = logger;
            }
    ...
    }
    
    public class DefaultController : WebControllerBase
        {
            private readonly ILogger _logger;
            public DefaultController(ILogger logger) : base(logger)
            {
                _logger = logger;
            }
    
        public override ActionResult Index(ContentModel model)
            {...}
    }
    
  • iNETZO 133 posts 496 karma points c-trib
    Oct 18, 2022 @ 07:01
    iNETZO
    0

    Hi Heather,

    We experience the same problem, only when a document type has a custom controller, errors are reported via the logger. Are you still using the above method or have you found another solution?

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Oct 18, 2022 @ 11:20
    Heather Floyd
    0

    Hi, I haven't built any new Umbraco 8 sites in awhile. I assume that is still the best method to use for Umbraco 8. For versions 9+, use dependency injection.

Please Sign in or register to post replies

Write your reply to:

Draft