且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在实体框架核心中抑制 SQL 查询日志记录

更新时间:2022-01-11 21:17:58

如果您使用内置记录器,您可以在 Program.cs 中为您的 ILoggingBuilder 添加过滤器.

If you're using built-in logger, you can add filter to you ILoggingBuilder in Program.cs.

所以,它看起来像:

WebHost.CreateDefaultBuilder(args)
    // ...
    .ConfigureLogging((context, logging) => {
        var env = context.HostingEnvironment;
        var config = context.Configuration.GetSection("Logging");
        // ...
        logging.AddConfiguration(config);
        logging.AddConsole();
        // ...
        logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
    })
    // ...
    .UseStartup<Startup>()
    .Build();