Copied to clipboard

Flag this post as spam?

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


  • Debasish Gracias 32 posts 163 karma points
    Sep 06, 2022 @ 10:18
    Debasish Gracias
    0

    How to get an ILogger in Composer

    Im trying to use ILogger inside a composer to log some information to the log file. If I register an ILogger with dependency injection inside the constructor, I get the below error:

    private readonly ILogger _logger;
            public ServerRegistrarComposer(ILogger logger)
            {
                _logger = logger;
            }
    

    Error:

    System.InvalidOperationException: 'Composer StarterKit.Core.Composers.ServerRegistrarComposer does not have a parameter-less constructor.'
    

    What is the right way to get an instance of ILogger here?

  • Debasish Gracias 32 posts 163 karma points
    Sep 08, 2022 @ 05:34
    Debasish Gracias
    101

    I was able to get the instance of ILogger and use it like below:

      public class ServerRegistrarComposer : IComposer
        {
            public void Compose(IUmbracoBuilder builder)
            {
                var logger = builder.BuilderLoggerFactory.CreateLogger<ServerRegistrarComposer>();
    
                logger.LogInformation("Hello!!!");          
            }
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft