serilog / serilog-expressions

An embeddable mini-language for filtering, enriching, and formatting Serilog events, ideal for use with JSON or XML configuration.
Apache License 2.0
193 stars 17 forks source link

support expressions for MinmimLevel.ControlBy #83

Closed DevAbsi closed 1 year ago

DevAbsi commented 2 years ago

Hi @nblumhardt, I have been using your package for doing some realtime configurations for serilog under blazor, I have an idea of configuring the minimum level for a specific client using my app, I have added a property with clientName using the enrichers of serilog to my logs, and now I want to add an expression for controlling the minimum value for the warning somethinkg like

"Using": [ "Serilog.Expressions" ],
    "LevelSwitches": {
      "$appLogLevel": "Information",
      "$appLogLevel2": "Debug"
    },
    "MinimumLevel": {
      "ControlledBy": "ClientName like 'martin' then $appLogLevel else $appLogLevel2"
    },

I have tested the package with the above example and it is not working. does the package support that functionality? if not, are you planning to support it?

nblumhardt commented 2 years ago

Hi @DevAbsi!

Minimum levels control whether events are generated or not, so there's no way to base one on an expression.

I think the feature you're looking for is filters, which can be used to remove events once generated. There's an example showing filtering with this library in the readme.

Hope this helps, Nick