Startup.cs
public class Startup { public static readonly ILoggerFactory efLogger = LoggerFactory.Create(builder => { builder.AddFilter((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole(); }); public void ConfigureServices(IServiceCollection services) { services.AddDbContext<EFCoreContext>(options => { options .UseSqlServer(Configuration.GetConnectionString(nameof(EFCoreContext))) .UseLoggerFactory(efLogger); }); } }
https://docs.microsoft.com/zh-cn/ef/core/miscellaneous/logging?tabs=v3