简体   繁体   English

在 Serilog 中仅显示调试级别日志

[英]Show only debug level logs in Serilog

I want to show only debug level of logs, but none of the other levels, below or above the debug level.我只想显示调试级别的日志,但不显示低于或高于调试级别的其他级别。 Also I want to do that in the configuration in appsettings.json, not in the startup class.我也想在 appsettings.json 的配置中做到这一点,而不是在启动 class 中。 Here is my appsettings.json file这是我的 appsettings.json 文件

 "Serilog": {
"MinimumLevel": {
  "Default": "Debug",
  "Override": {
    "System": "Debug",
    "Microsoft": "Debug"
  }
},
"WriteTo": [
  {
    "Name": "Seq",
    "Args": {
      "serverUrl": "http://localhost:5341/",
      "compact": true
    }
  },
  {
    "Name": "Console"
  },
  {
    "Name": "File",
    "Args": {
      "path": "D:\\dev.SmartCity.Peafowls.Logs\\PeafowlsLog_.txt",
      "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}",
      "rollingInterval": "Day",
      "rollOnFileSizeLimit": true,
      "fileSizeLimitBytes": 4194304
    }
  }
],
"Enrich": [ "FromLogContext" ] }

Check this answer.检查这个答案。 You can filter messages by level.您可以按级别过滤消息。

Like this example:像这个例子:

{
  "Serilog": {
    "Using": ["Serilog.Settings.Configuration"],
    "Filter": [
      {
        "Name": "ByExcluding",
        "Args": {
          "expression": "EndsWith(RequestPath, '/SomeEndpoint')"
        }
      }
    ]

from Github source code.来自Github源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM