How to register ILogger for injection in ASP.NET MVC 6

前端 未结 3 2055
你的背包
你的背包 2021-02-06 20:55

I have a ASP.NET MVC 6 (beta-4) app.

public void ConfigureServices(IServiceCollection services)
{
    // Logging
    services.AddLogging();

    // ...
}

publi         


        
3条回答
  •  一个人的身影
    2021-02-06 21:43

    The services.AddLogging(); didn't worked for me, so I added these two statements to ConfigureServices:

    services.AddSingleton();
    services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
    

    Now the DI container is happy and everything works.

提交回复
热议问题