Skip to content

Support LevelAlias names in configuration parsing#465

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

Support LevelAlias names in configuration parsing#465
nblumhardt merged 2 commits intoserilog: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

Copy link
Copy Markdown
Member

@nblumhardt nblumhardt left a comment

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
Copy link
Copy Markdown

tvardero commented Feb 12, 2026

@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
Copy link
Copy Markdown
Member

Numpsy commented Feb 12, 2026

@tvardero
Copy link
Copy Markdown

tvardero commented Feb 27, 2026

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
Copy link
Copy Markdown
Member

bartelink commented Mar 24, 2026

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

@nblumhardt nblumhardt mentioned this pull request Apr 30, 2026
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