Update logging source generator to match runtime PR #124589 (ref readonly/params/scoped)#7333
Open
Update logging source generator to match runtime PR #124589 (ref readonly/params/scoped)#7333
Conversation
…ms (runtime#124589) Co-authored-by: svick <287848+svick@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update telemetry logging source generator for changes in runtime PR
Update telemetry logging source generator: support Feb 23, 2026
ref readonly/scoped, forbid params
svick
approved these changes
Feb 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ports changes from dotnet/runtime#124589 to add support for ref readonly and scoped parameter modifiers in the logging source generator, and adds a new diagnostic (LOGGEN039) to forbid params parameters which were previously silently generating broken code.
Changes:
- Added support for
ref readonlyparameters by handlingRefKind.RefReadOnlyParameterin the parser and preserving theref readonlyqualifier in generated signatures - Added support for
scopedmodifier by trackingIsScopedin theLoggingMethodParametermodel and emitting it in the generated parameter list - Added LOGGEN039 diagnostic to produce a compile-time error for
paramsparameters instead of silently generating incorrect code
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Shared/DiagnosticIds/DiagnosticIds.cs |
Added LOGGEN039 diagnostic ID constant |
src/Generators/Microsoft.Gen.Logging/Parsing/Resources.resx |
Added error message resources for params parameter diagnostic |
src/Generators/Microsoft.Gen.Logging/Parsing/Resources.Designer.cs |
Auto-generated resource accessor code for LOGGEN039 messages |
src/Generators/Microsoft.Gen.Logging/Parsing/DiagDescriptors.cs |
Added LoggingMethodParameterParams diagnostic descriptor |
src/Generators/Microsoft.Gen.Logging/Parsing/Parser.cs |
Added params detection, ref readonly support, and scoped tracking |
src/Generators/Microsoft.Gen.Logging/Model/LoggingMethodParameter.cs |
Added IsScoped field to track scoped modifier |
src/Generators/Microsoft.Gen.Logging/Emission/Emitter.Method.cs |
Updated parameter generation to emit scoped prefix when needed |
test/Generators/Microsoft.Gen.Logging/Unit/ParserTests.LogMethod.cs |
Added unit tests for params, ref readonly, and scoped modifiers |
test/Generators/Microsoft.Gen.Logging/TestClasses/RefReadOnlyParameterTestExtensions.cs |
Added test class with ref readonly and scoped ref readonly methods |
test/Generators/Microsoft.Gen.Logging/Generated/LogMethodTests.cs |
Added runtime test for ref readonly parameters |
docs/list-of-diagnostics.md |
Documented LOGGEN039 diagnostic |
Files not reviewed (1)
- src/Generators/Microsoft.Gen.Logging/Parsing/Resources.Designer.cs: Language not supported
…oped Co-authored-by: svick <287848+svick@users.noreply.github.com>
Copilot
AI
changed the title
Update telemetry logging source generator: support
Update logging source generator to match runtime PR #124589 (ref readonly/params/scoped)
Feb 24, 2026
ref readonly/scoped, forbid params
svick
approved these changes
Feb 24, 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.
Aligns
Microsoft.Gen.Loggingsource generator with dotnet/runtime#124589, which changed howparams,ref readonly, andscopedparameter modifiers are handled in[LoggerMessage]methods.Key changes
paramsandscopedchecks that emit newLOGGEN039diagnostic; addedRefKind.RefReadOnlyParameterhandling. Scoped check is ordered after theref/outcheck becauseoutparameters are implicitly scoped in C# 11+.IsScopedfromLoggingMethodParameter(no longer needed since scoped is forbidden rather than supported).scopedprefix generation fromGenParameters.LOGGEN039covers bothparamsandscopedmodifiers.Example
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow