serilog minimumlevel 覆盖不适用于控制台但适用于滚动文件

serilog minimumlevel override not working for console but does for rolling file

我有以下代码,它只成功地记录了排除 Microsoft 和其他系统日志的信息日志,但控制台仍然写入了一些我想排除的信息

  "Serilog": {
"MinimumLevel": {
  "Default": "Information",
  "Override": {
    "Microsoft": "Warning",
    "System": "Warning"
  }
},
"WriteTo": [
  {
    "Name": "Console",
    "Args": { "outputTemplate": "[{Timestamp:HH:mm:ss.fff}] {Level:u3} - {Message}{NewLine}{Exception}" }
  },
  {
    "Name": "RollingFile",
    "Args": {
      "pathFormat": "log-{Date}.log",
      "outputTemplate": "[{Timestamp:dd/MM/yy HH:mm:ss.fff z}] {Level:u3} {Message}{NewLine}{Exception}"
    }
  }
]

},

另外,这里是根据上述设置写入到控制台而不是滚动文件的内容

info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
  Entity Framework Core 2.0.1-rtm-125 initialized 'CryptoAlertContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (26ms) [Parameters=[@__p_0='?'], CommandType='Text', CommandTimeout='30']
  SELECT TOP(@__p_0) [x].[CoinId], [x].[Icon], [x].[LastPriceBtc], [x].[LastPriceUsd], [x].[LastUpdated], [x].[Name], [x].[Rank], [x].[Symbol]
  FROM [Coins] AS [x]
  ORDER BY [x].[Rank]

您的程序启动代码中似乎缺少 UseSerilog():您显示的控制台输出来自默认的 ASP.NET 日志记录提供程序,而不是 Serilog。