Support LevelAlias names in configuration parsing - #465
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 |
Updated [Serilog](https://github.com/serilog/serilog) from 4.3.1 to 4.4.0. <details> <summary>Release notes</summary> _Sourced from [Serilog's releases](https://github.com/serilog/serilog/releases)._ ## 4.4.0 ## What's Changed * Emit SelfLog warning when extra arguments are provided by @matantsach in serilog/serilog#2222 * dont WriteQuotedJsonString for null by @SimonCropp in serilog/serilog#2216 * Pin System.Security.Cryptography.Xml to 8.0.3 in tests by @ArieGato in serilog/serilog#2232 * Route optional interfaces through OptionalInterfaceForwardingSink for restricted sinks by @ArieGato in serilog/serilog#2234 * `SelfMetrics` by @nblumhardt in serilog/serilog#2237 ## New Contributors * @matantsach made their first contribution in serilog/serilog#2222 * @ArieGato made their first contribution in serilog/serilog#2232 **Full Changelog**: serilog/serilog@v4.3.1...v4.4.0 Commits viewable in [compare view](serilog/serilog@v4.3.1...v4.4.0). </details> Updated [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) from 10.0.0 to 10.0.1. <details> <summary>Release notes</summary> _Sourced from [Serilog.Settings.Configuration's releases](https://github.com/serilog/serilog-settings-configuration/releases)._ ## 10.0.1 ## What's Changed * Support LevelAlias names in configuration parsing by @mohammed-saalim in serilog/serilog-settings-configuration#465 * Fix: Update ConditionalSink expression syntax in sample app by @gyurebalint in serilog/serilog-settings-configuration#470 * issue-468: Fix empty/whitespace string converting to array type by @gyurebalint-CID in serilog/serilog-settings-configuration#469 * Add WriteTo.FallbackChain and WriteTo.Fallible support in configuration by @ArieGato in serilog/serilog-settings-configuration#474 * Fix/issue 441 by @gyurebalint in serilog/serilog-settings-configuration#471 * Support C# 13 params collections (IEnumerable<T>, List<T>) by @gyurebalint in serilog/serilog-settings-configuration#478 ## New Contributors * @mohammed-saalim made their first contribution in serilog/serilog-settings-configuration#465 * @gyurebalint made their first contribution in serilog/serilog-settings-configuration#470 * @gyurebalint-CID made their first contribution in serilog/serilog-settings-configuration#469 * @ArieGato made their first contribution in serilog/serilog-settings-configuration#474 **Full Changelog**: serilog/serilog-settings-configuration@v10.0.0...v10.0.1 Commits viewable in [compare view](serilog/serilog-settings-configuration@v10.0.0...v10.0.1). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.