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
    21 days ago
    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 290 posts 1278 karma points
    21 days ago
    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
    21 days ago
    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
    21 days ago
    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

Please Sign in or register to post replies

Write your reply to:

Draft