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

时间:2017-11-20 14:47:30

标签: c# asp.net-core serilog

我有以下代码,它们成功地只记录了排除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]

1 个答案:

答案 0 :(得分:0)

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