我有一个基本测试控制器,可以创建一个记录器,如下所示:
public class WSTestController
{
protected readonly ILogger _log;
protected readonly HttpClient _client;
protected readonly IServiceCollection _services;
public WSTestController() {
_log = new LoggerFactory().AddConsole().CreateLogger(this.GetType().Name);
var testContext = new TestContext();
_client = testContext.Client;
}
这在netcore 2.0中可以正常工作,但在netcore 2.1中我遇到以下错误:
controllers/WSTestController.cs(22,40): error CS1061:
'LoggerFactory' does not contain a definition for 'AddConsole' and no accessible extension method 'AddConsole' accepting a first argument of type 'LoggerFactory' could be found
(are you missing a using directive or an assembly reference?) [[...]/src/mtss-ws.integrationtests/mtss-ws.integrationtests.csproj]
如何在netvore 2.1中手动实例化控制台记录器(没有DI)?