Serilog : how do you specify a filter expression in config file

You need to use Serilog.Filters.Expressions for this:

Install-Package Serilog.Filters.Expressions

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.

Tags:

Serilog