Skip to content

Logging source generator should support generic methods (SYSLIB1011 should be lifted) #90589

Closed

Description

@alexrp

From this section:

Logging methods cannot be generic.

This seems to be an unnecessary restriction that also works against the whole notion of high-performance logging.

I would like to be able to write a logging method like so:

[LoggerMessage(0, LogLevel.Trace, "C -> S {EndPoint}: {Channel}:{Code} ({Length} bytes)")]
public static partial void PacketReceived<TCode>(ILogger logger, IPEndPoint endPoint, ConnectionChannel channel, TCode code, int length)
    where TCode : struct, Enum;

Here, the type argument for TCode depends on the value of Channel. Of course, I could make the logging method non-generic and accept an Enum-typed value, but then I get unconditional boxing... certainly not what I want when logging in a fairly hot path. Alternatively, I could duplicate the method for as many TCodes as I have (which is what I'll do for now), but this is not great either, for all the expected maintenance reasons.

I think this restriction should just be lifted. Maybe there's a good reason for it, but if there is, it's not obvious to me.

Activity

  1. ghost added
    untriaged
    on Aug 15, 2023
  2. added this to the Future milestone on Aug 15, 2023
  3. ghost removed
    untriaged
    on Aug 15, 2023
  4. added
    source-generator
    on Nov 20, 2023
  5. cincuranet commented on Feb 10, 2026

    @cincuranet
    Contributor

    Triage: Niche scenario, but would be nice to have it one day.

  6. added
    in-pr
    on Feb 20, 2026
  7. modified the milestones: Future, 11.0.0 on Feb 26, 2026
  8. added a commit that references this issue on Feb 27, 2026
    e1c62a5
  9. locked and limited conversation to collaborators on Mar 30, 2026
  10. removed
    in-pr
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Extensions-Loggingsource-generator

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions