如何防止记录我的所有实体框架 SQL 查询?

问题描述 投票:0回答:1

我正在使用

Serilog.Sinks.File
,我的所有 SQL 查询都会被记录。

这是我的配置代码:

// Configure Serilog
Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(context.Configuration)
    .WriteTo.File(Path.Combine(applicationContext.GetWorkingPath(), "TrackTrace.WorkerServices.log"),
        rollOnFileSizeLimit: true)
    .CreateLogger();

这是我的 appsettings.json

"Logging": {
  "LogLevel": {
    "Default": "Information",
    "Hangfire": "Information",
    "Microsoft": "Warning",
    "Microsoft.Hosting.Lifetime": "Information"
}

将默认的 Microsoft 前缀设置为

Warning
,我希望这能够消除所有 SQL 查询。我错过了什么?

更新

这是我配置数据库的方式。

// Configure database
services.AddDbContext<TrackTraceDbContext>(options =>
{
    options.UseSqlServer(
        connectionString,
        builder => builder.MigrationsAssembly(nameof(TTRailtraxEntities)));
});
c# .net-core serilog serilog-sinks-file
1个回答
0
投票

AFAIK Serilog 不使用默认配置部分,请尝试将设置移至 Serilog -> MaximumLevel -> Override:

  "Serilog": {
    "MinimumLevel": {
        "Default": "Information",
        "Override": {
            "Microsoft": "Warning",
            "System": "Warning"
        }
    },
© www.soinside.com 2019 - 2024. All rights reserved.