如何在外部 JSON 配置文件中配置 Serilog 的 ContainsKey-Filter?

How to configure Serilog's ContainsKey-Filter in a external JSON config file?

如何在外部 applicationsettings.json 文件中配置过滤器 lc.Filter.ByIncludingOnly(lc => lc.Properties.ContainsKey("log_gp")?我试过了

  "Filter": [
    {
      "Name": "ByIncludingOnly",
      "Args": {
        "expression": "Contains(Properties, 'log_gp')"
      }
    }
  ]

但没有成功。 谢谢

dotnet add package serilog.expressions

然后:

  "Using": ["Serilog.Expressions"],
  "Filter": [
    {
      "Name": "ByIncludingOnly",
      "Args": {
        "expression": "IsDefined(log_gp)"
      }
    }
  ]