Serilog:如何在配置文件中指定过滤器表达式 [英] Serilog : how do you specify a filter expression in config file

查看:275
本文介绍了Serilog:如何在配置文件中指定过滤器表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 appsettings .json 文件中指定此过滤器

I am trying to specify this filter in the appsettings .json file

.Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore.Hosting.Internal.WebHost"))

上述语法在 c# 中指定时有效

The above syntax works when specified in c#

但是尝试在 json 文件中指定相同的内容不起作用.

But trying to specify the same in a json file does not work.

"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "Matching.FromSource = 'Microsoft.AspNetCore.Hosting.Internal.WebHost'"
}
}

推荐答案

您需要使用 Serilog.Filters.Expressions:

Install-Package Serilog.Filters.Expressions

appsettings.json 中的过滤器部分如下所示:

The filter section in appsettings.json looks like:

"Filter": [
  {
    "Name": "ByExcluding",
    "Args": {
      "expression": "SourceContext = 'Microsoft.AspNetCore.Hosting.Internal.WebHost'"
    }
  }
],

在这种特定情况下,我建议考虑级别覆盖作为更有效地关闭特定命名空间的替代方法.

In this specific case, I'd suggest considering level overrides as an alternative that will turn off a specific namespace more efficiently.

这篇关于Serilog:如何在配置文件中指定过滤器表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆