Copied to clipboard

Flag this post as spam?

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


  • Allan Haugsted 14 posts 104 karma points
    Sep 03, 2019 @ 08:26
    Allan Haugsted
    0

    Hi

    I'm trying to track down whats going on inside some of my components, each of which controls a custom mvc route with a custom handler.

    How do I access or obtain access to the serilog logger (from within the component) which outputs to /app_data/logs? I have tried just injecting an ILogger, but that fails horribly and prevents the site from booting.

    /Allan

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Sep 03, 2019 @ 09:46
    Shaishav Karnani from digitallymedia.com
    0

    Hi Allan,

    Please can you share the code as iLogger is the way to go and it worked for us.

    Regards,

    Shaishav

  • Allan Haugsted 14 posts 104 karma points
    Sep 03, 2019 @ 11:50
    Allan Haugsted
    0
    public class ProductRouteComponent : IComponent
    {
        private readonly IDomainService _domainService;
    
        private readonly ILogger _logger;
    
        public ProductRouteComponent(IDomainService domainService, ILogger logger)
        {
            _domainService = domainService;
            _logger = logger;
        }
    
        public void Initialize()
        {
            _logger.Info("hello");
        }
    
        public void Terminate()
        {
        }
    }
    
  • Allan Haugsted 14 posts 104 karma points
    Sep 03, 2019 @ 11:51
    Allan Haugsted
    0

    The above will fail with the following:

    ystem.InvalidOperationException: Unresolved dependency [Target Type: An.Web.Components.ProductRouteComponent], [Parameter: logger(ClientDependency.Core.Logging.ILogger)], [Requested dependency: ServiceType:ClientDependency.Core.Logging.ILogger, ServiceName:]

    I have also tried adding the Microsoft.Extensions.Logging.Abstractions package and used the ILogger

  • HBSequence 6 posts 77 karma points
    May 22, 2020 @ 14:54
    HBSequence
    1

    Hi Allan. I just had the same issue in a Surface Controller, which went away when I added this using statement: using Umbraco.Core.Logging.

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    May 23, 2020 @ 19:34
    Anders Bjerner
    0

    Yes, as HBSequence is onto, you need to specify the correct namespace.

    With the various DLLs shipping with Umbraco, there are a few different interfaces called ILogger.

    From the stack trace posted, it seems that you've used ClientDependency's ILogger instead of Umbraco's ILogger.

    The correct namespace is Umbraco.Core.Logging.

    image

Please Sign in or register to post replies

Write your reply to:

Draft