Skip to content

Microsoft.Extensions.Logging.LoggerMessageAttribute remarks specify unnecessary constraint (.net 10/11) #130319

Closed

Description

@dodexahedron

Describe the issue or suggestion

Type of issue
Other (describe below)

Description
(Re-posting using the general template, since I'm unable to re-open dotnet/dotnet-api-docs#128641)

The remarks for theMicrosoft.Extensions.Logging.LoggerMessageAttribute specify that the partial method MUST have a LogLevel parameter. This is not true, if it is provided in the attribute constructor already. And even if it isn't, the source generator still generates a valid method body, and it defaults to the None level.

Page URL
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loggermessageattribute?view=net-10.0-pp

Content source URL
https://github.com/dotnet/dotnet-api-docs-temp/blob/live/xml/Microsoft.Extensions.Logging/LoggerMessageAttribute.xml

Document Version Independent Id
9770b029-6b28-e408-e3e2-33d23fa0a765

Platform Id
9a775e96-1da2-d1f5-62cc-55f14136030d

Article author
@dotnet-bot

Footnotes

  1. The Learn Feedback Control issue template used when clicking the Open documentation issue link on the doc seems broken, at least on Edge 150 on Windows 11. It is impossible to edit the text in the comment box (just gets reset to the placeholder text no matter what you do). And then it got auto-closed for that reason. And then the bot said feel free to re-open, but I don't have permission to do so. So, here's a new issue. ↩

Activity

  1. added
    untriaged
    on Jul 7, 2026
  2. gewarren commented on Jul 7, 2026

    @gewarren
    Contributor

    Thanks @dodexahedron , I opened dotnet/dotnet-api-docs#12866 to fix the template issue.

  3. dotnet-policy-service commented on Jul 7, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-extensions-logging
    See info in area-owners.md if you want to be subscribed.

  4. transferred this issue fromdotnet/runtimeon Jul 7, 2026
  5. removed
    untriaged
    on Jul 7, 2026
  6. added
    untriaged
    on Jul 7, 2026
  7. removed
    untriaged
    on Jul 7, 2026
  8. added this to the 11.0.0 milestone on Jul 7, 2026
  9. added
    in-pr
    on Jul 7, 2026
  10. tarekgh commented on Jul 7, 2026

    @tarekgh
    Member

    Thanks for reporting this. You're right about the main point: the log level doesn't have to be a method parameter, it can be set on the attribute (via a constructor argument or the Level property), so the old remark saying it must be a parameter was wrong. #130320 fixes the wording.

    One correction on the second part though: a log level is still required, it just has to be provided in one of those two places. If you omit it from the attribute and don't have a LogLevel parameter, the source generator reports SYSLIB1017 (MissingLogLevel) and doesn't generate the method, so it doesn't silently default to None. You can see that in the generator here: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs#L516

    So the corrected remark reads: the method must specify a log level, either on the attribute or as a LogLevel parameter.

  11. dodexahedron commented on Jul 7, 2026

    @dodexahedron
    Author

    Cool. Sounds ideal.

    And thanks for the clarification on point 2. I could have sworn I saw it do it, but I must have been looking at the attribute itself or something and mixed that up with the generated code in my head on the way from VS to the docs to here. 😅

    Also, confirmed that dotnet/dotnet-api-docs#12866 does appear to have made filling out that template possible again. 👍 Thanks @gewarren

  12. locked and limited conversation to collaborators on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Extensions-Loggingin-pr

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions