Emit SelfLog warning when extra arguments are provided#2222
Merged
nblumhardt merged 1 commit intoFeb 15, 2026
Conversation
When a message template has no properties but arguments are supplied
(e.g. `logger.Information("Message", 42)`), no SelfLog diagnostic
was emitted, making it difficult to detect mismatched log calls.
This adds a SelfLog.WriteLine call in ConstructNamedProperties when
the template has no named properties but parameters were provided.
Fixes serilog#1600
Member
|
Looks great; thanks! (And thanks @jandresleiva for the earlier investigation 👍) |
Merged
This was referenced Jul 10, 2026
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1600
When a message template has no properties but arguments are supplied (e.g.
logger.Information("Argument extra", 42)), noSelfLogdiagnostic was emitted, making it difficult to detect mismatched log calls at runtime.Changes
PropertyBinder.ConstructNamedProperties: Added aSelfLog.WriteLinecall whenNamedPropertiesisnullbutmessageTemplateParameters.Length > 0ProvidingMoreParametersThanNamedPropertiesInTheTemplateWillSelfLog— verifiesSelfLogfires when more args than named propertiesProvidingParametersWhenTemplateHasNoPropertiesWillSelfLog— verifiesSelfLogfires for the exact scenario in No SelfLog event when there are extra arguments #1600Performance
The added check (
messageTemplateParameters.Length > 0) only executes in the early-return path when the template has no properties at all. On the normal hot path (templates with properties), there is zero overhead. This aligns with @jandresleiva's earlier benchmark analysis showing negligible impact.Testing
All existing tests pass. Two new tests added covering both the reported scenario and the related "more args than properties" case.