Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

serilog

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

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

The above syntax works when specified in c#

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'"
}
}
like image 214
kolhapuri Avatar asked May 17 '17 13:05

kolhapuri


1 Answers

You need to use Serilog.Expressions for this:

Install-Package Serilog.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.

like image 196
Nicholas Blumhardt Avatar answered Nov 09 '22 16:11

Nicholas Blumhardt