Skip to content

Comments

Update logging source generator to match runtime PR #124589 (ref readonly/params/scoped)#7333

Open
Copilot wants to merge 3 commits intomainfrom
copilot/update-telemetry-logging-generator-again
Open

Update logging source generator to match runtime PR #124589 (ref readonly/params/scoped)#7333
Copilot wants to merge 3 commits intomainfrom
copilot/update-telemetry-logging-generator-again

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Aligns Microsoft.Gen.Logging source generator with dotnet/runtime#124589, which changed how params, ref readonly, and scoped parameter modifiers are handled in [LoggerMessage] methods.

Key changes

  • Parser — Added params and scoped checks that emit new LOGGEN039 diagnostic; added RefKind.RefReadOnlyParameter handling. Scoped check is ordered after the ref/out check because out parameters are implicitly scoped in C# 11+.
  • Model — Removed IsScoped from LoggingMethodParameter (no longer needed since scoped is forbidden rather than supported).
  • Emitter — Removed scoped prefix generation from GenParameters.
  • Diagnostics — New LOGGEN039 covers both params and scoped modifiers.

Example

// ref readonly — now supported, qualifier preserved in generated method
[LoggerMessage(0, LogLevel.Info, "Value: {x}")]
static partial void LogValue(ILogger logger, ref readonly int x); // ✅

// params — new LOGGEN039 error
[LoggerMessage(1, LogLevel.Info, "Values")]
static partial void LogValues(ILogger logger, params int[] values); // ❌ LOGGEN039

// scoped — new LOGGEN039 error  
[LoggerMessage(2, LogLevel.Info, "Value: {x}")]
static partial void LogScoped(ILogger logger, scoped ref readonly int x); // ❌ LOGGEN039

✨ 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

…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 ref readonly/scoped, forbid params Feb 23, 2026
Copilot AI requested a review from svick February 23, 2026 15:23
@svick svick marked this pull request as ready for review February 23, 2026 15:41
@svick svick requested review from a team as code owners February 23, 2026 15:41
Copilot AI review requested due to automatic review settings February 23, 2026 15:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 readonly parameters by handling RefKind.RefReadOnlyParameter in the parser and preserving the ref readonly qualifier in generated signatures
  • Added support for scoped modifier by tracking IsScoped in the LoggingMethodParameter model and emitting it in the generated parameter list
  • Added LOGGEN039 diagnostic to produce a compile-time error for params parameters 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

@svick svick marked this pull request as draft February 24, 2026 10:13
…oped

Co-authored-by: svick <287848+svick@users.noreply.github.com>
Copilot AI changed the title Update telemetry logging source generator: support ref readonly/scoped, forbid params Update logging source generator to match runtime PR #124589 (ref readonly/params/scoped) Feb 24, 2026
Copilot AI requested a review from svick February 24, 2026 13:11
@svick svick marked this pull request as ready for review February 24, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants