Autofac.Extras.NLog icon indicating copy to clipboard operation
Autofac.Extras.NLog copied to clipboard

Does SimpleNLogModule exist?

Open FixRM opened this issue 1 year ago • 1 comments

Hello and thank you for this tool. I have a problem with resolving ILogger with IServiceProvider. My implementation is pretty simple:

    public class ServiceProvider : IServiceProvider
    {
        private readonly ILifetimeScope scope;

        public ServiceProvider(ILifetimeScope scope)
        {
            this.scope = scope;
        }

        public object GetService(Type serviceType)
        {
            return scope.Resolve(serviceType);
        }
    }

and this is registration part:

var builder = new ContainerBuilder();
builder.RegisterModule<NLogModule>();
builder.RegisterType<ServiceProvider>().As<IServiceProvider>();

Types registered with RegisterType are resolved well, but when I try to resolve ILogger I got "The requested service 'NLog.ILogger' has not been registered" exception. If ILogger is injected as constructor parameter then is resolved well as part of ASP.NET DI. What am I doing wrong?

Your Readme says that there is SimpleNLogModule that "is useful when ILogger resolved from Service Locator". But it looks like it doesn't exist any more.

FixRM avatar Jan 26 '24 11:01 FixRM

Hello @ziyasal, can you help with that?

FixRM avatar Feb 06 '24 11:02 FixRM