Unable to resolve ILogger from Microsoft.Extensions.Logging

前端 未结 7 1030
太阳男子
太阳男子 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:42

    Based on @Barry answer above found out how to register generic log provider for Microsoft.Extensions.DependencyInjection:

    var services = new ServiceCollection()
                                .AddLogging(logging => logging.AddConsole())
                                .BuildServiceProvider();
    
    services.AddSingleton()
    services.Add(ServiceDescriptor.Describe(typeof(ILogger<>),typeof(Logger<>),ServiceLifetime.Scoped))
    

提交回复
热议问题