.NET Core / EF.Core 3+ 将控制台日志记录添加到 DbContext
.NET Core / EF.Core 3+ add Console logging to DbContext
我想知道如何在不收到 "obsolete" 警告的情况下将控制台日志记录添加到 EF.Core。
鉴于:
DbContextOptionsBuilder<BenchmarkDbContext> builder = ...;
我试过了:
builder.UseLoggerFactory(new LoggerFactory().AddConsole())
并尝试过:
var factory = new LoggerFactory();
factory.AddProvider(new ConsoleLoggerProvider((a, b) => true, true));
builder.UseLoggerFactory(factory)
我认为在 EFCore 中更改了记录器的初始化 3.x。试试这个:
public static readonly ILoggerFactory factory
= LoggerFactory.Create(builder => { builder.AddConsole(); });
我想知道如何在不收到 "obsolete" 警告的情况下将控制台日志记录添加到 EF.Core。
鉴于:
DbContextOptionsBuilder<BenchmarkDbContext> builder = ...;
我试过了:
builder.UseLoggerFactory(new LoggerFactory().AddConsole())
并尝试过:
var factory = new LoggerFactory();
factory.AddProvider(new ConsoleLoggerProvider((a, b) => true, true));
builder.UseLoggerFactory(factory)
我认为在 EFCore 中更改了记录器的初始化 3.x。试试这个:
public static readonly ILoggerFactory factory
= LoggerFactory.Create(builder => { builder.AddConsole(); });