Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger`1[WebApplication1.Startup]'

前端 未结 5 2190
轮回少年
轮回少年 2021-02-05 12:29

I created an ASP.NET Core 3.0 Web Application with the default template in Visual Studio 2019 Preview 2.2 and tried to inject an ILogger in Startup:

namespace We         


        
5条回答
  •  忘了有多久
    2021-02-05 13:03

    This can be solved by registering the ILogger manually to use the Startup class as type.

    Example:

    public void ConfigureServices(IServiceCollection services)
    {
        // Normal AddLogging
        services.AddLogging();
    
        // Additional code to register the ILogger as a ILogger where T is the Startup class
        services.AddSingleton(typeof(ILogger), typeof(Logger)); 
      
        // ...
    }
    

提交回复
热议问题