Skip to content

Support LevelAlias names in configuration parsing - #465

Merged
nblumhardt merged 2 commits into
serilog:devfrom
mohammed-saalim:add-levelalias-parsing
Jan 20, 2026
Merged

Support LevelAlias names in configuration parsing#465
nblumhardt merged 2 commits into
serilog:devfrom
mohammed-saalim:add-levelalias-parsing

Conversation

@mohammed-saalim

Copy link
Copy Markdown
Contributor

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:

InvalidOperationException: The value Off is not a valid Serilog level.

Changes

  • Modified ParseLogEventLevel() method to check for LevelAlias names first
  • Handles "Off", "Minimum", and "Maximum" (case-insensitive)
  • Falls back to enum parsing for standard log levels (Verbose, Debug, Information, etc.)

Testing

  • ✅ All existing tests pass (1191/1191)
  • ✅ Manual testing confirmed "MinimumLevel": "Off" works from configuration
  • ✅ Build successful across all target frameworks

This follows the guidance from @nblumhardt in the issue thread.

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.
@nblumhardt

Copy link
Copy Markdown
Member

This looks good, thanks. Would it be possible to add one small test (i.e. an xUnit theory) that checks ParseLogEventLevel still handles the original values, plus the expected new ones? It will be necessary to mark ParseLogEventLevel as internal for this.

- 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
@mohammed-saalim

Copy link
Copy Markdown
Contributor Author

Done! Added tests as requested. All pass locally. @nblumhardt

@nblumhardt nblumhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks @mohammed-saalim 👍

@nblumhardt
nblumhardt merged commit e0b845c into serilog:dev Jan 20, 2026
1 check passed
@tvardero

tvardero commented Feb 12, 2026

Copy link
Copy Markdown

@mohammed-saalim @nblumhardt should json schema for appsettings.json be updated as well?
For intellisense / autocompletion.

I know Rider has it for Serilog, but i'm not sure where it gets it.

@nblumhardt

Copy link
Copy Markdown
Member

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 :-)

@Numpsy

Numpsy commented Feb 12, 2026

Copy link
Copy Markdown
Member

@tvardero

tvardero commented Feb 27, 2026

Copy link
Copy Markdown

Is that the one linked from #404?

@Numpsy, indeed it was!
I have made a PR to schemastore, it was already merged and level "Off" is not being suggested in Rider.

Thank you

@tvardero

Copy link
Copy Markdown

@nblumhardt Sorry to rush, but can this be released as patch?

@bartelink

bartelink commented Mar 24, 2026

Copy link
Copy Markdown
Member

@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 master)

tetsuo13 pushed a commit to tetsuo13/TeamsStatusPub that referenced this pull request Jul 17, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't disable ASP.NET Core Activity due to missing None log level

5 participants