Setting the MinimumLevel in Serilog: is it possible to use wildcards/regex the namespace ?
Let's assume that I have my own namespaces with different casing, which need both to be logged on Information.
Can this be done via the configuration like this?
"SeriLog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Default": "Warning",
"MyNameSpace|MYNameSpace": "Information"
}
}
}
Or is this only possible by specifying both?
"SeriLog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Default": "Warning",
"MyNameSpace": "Information",
"MYNameSpace": "Information"
}
}
}
The minimum level override feature does not support wildcards/regex as of this writing. It only supports simple (case-sensitive) partial matching. You can see how it works in the source code.
Declaring the two different namespaces as your second example is the way to go.
You can also exclude some log entries using Serilog.Expressions https://github.com/serilog/serilog/issues/1786#issuecomment-1487933383
I.e. set the minimum level for System.Net.Http.HttpClient
to allow Information though, but use Filter.ByExcluding(...)
and e.g. an expression to exclude SourceContext like 'System.Net.Http.HttpClient.%.LogicalHandler'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With