Unable to resolve ILogger from Microsoft.Extensions.Logging

前端 未结 7 1028
太阳男子
太阳男子 2021-02-02 04:56

I\'ve configured my console application\'s Main like so

var services = new ServiceCollection()
                .AddLogging(logging => logging.Add         


        
7条回答
  •  一生所求
    2021-02-02 05:48

    This answer isn't necessarily for .net Core or whatever dependency injection is being used by the poster. I ran across this searching for a way to fix this error using Autofac in an asp.net forms web application. The answer of logging not being "registered by default" led me to add this to my registrations:

    builder.RegisterType().As().SingleInstance();
    builder.RegisterGeneric(typeof(Logger<>)).As(typeof(ILogger<>)).SingleInstance();
    

    And now it works for me. This is the second time I searched for this answer and ended up here, I forgot how I fixed it the first time. So I thought I'd post my answer.

提交回复
热议问题