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

前端 未结 5 2158
轮回少年
轮回少年 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 12:48

    If you want to log things after the Configure() has been called, you can still inject the ILogger via method injection (as opposed to the preferred constructor injection:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger logger)
    {
         _logger = logger;
         ...
    }
    

提交回复
热议问题