Support LevelAlias names in configuration parsing#465
Support LevelAlias names in configuration parsing#465nblumhardt merged 2 commits intoserilog:devfrom
Conversation
Fixes serilog#461 Updates ParseLogEventLevel() to accept LevelAlias values (Off, Minimum, Maximum) before attempting to parse as LogEventLevel enum. This allows users to set 'MinimumLevel': 'Off' in appsettings.json to completely disable logging, which previously failed with an exception.
|
This looks good, thanks. Would it be possible to add one small test (i.e. an xUnit theory) that checks |
- Mark ParseLogEventLevel as internal for testability - Add theory tests covering all LogEventLevel enum values - Add theory tests covering LevelAlias values (Off, Minimum, Maximum) - Add tests for case insensitivity - Add tests for invalid value handling
|
Done! Added tests as requested. All pass locally. @nblumhardt |
nblumhardt
left a comment
There was a problem hiding this comment.
Great! Thanks @mohammed-saalim 👍
|
@mohammed-saalim @nblumhardt should json schema for appsettings.json be updated as well? I know Rider has it for Serilog, but i'm not sure where it gets it. |
|
Great suggestion, thanks; I'm not sure where this comes from either - a PR would be welcome if anyone has a chance to figure it out :-) |
|
Is that the one linked from #404? e.g. https://github.com/SchemaStore/schemastore/blob/e24defd47bd4942d34a363d4ff09efe0a8cbfeea/src/schemas/json/appsettings.json#L808 (Ithink that' what VCode uses anyway) |
@Numpsy, indeed it was! Thank you |
|
@nblumhardt Sorry to rush, but can this be released as patch? |
|
@tvardero the PR got merged into dev, which triggers an auto-publish of a -dev prerelease; see https://www.nuget.org/packages/serilog.settings.configuration Standard protocol is for the developer and/others to take it for a spin and validate (commenting or raising an issue if there are any anomalies), and then it's included in the next non-preview release (which is off |
Fixes #461
Summary
Updates ParseLogEventLevel() in ConfigurationReader.cs to accept LevelAlias values (
Off, Minimum,Maximum) before attempting to parse as LogEventLevel enum.This allows users to set
"MinimumLevel": "Off"in appsettings.json to completely disable logging, which previously failed with:Changes
Testing
"MinimumLevel": "Off"works from configurationThis follows the guidance from @nblumhardt in the issue thread.