Skip to content

Add support for logging with more than 6 arguments at runtime #55525

Closed as not planned

Description

@maryamariyan

Background and Motivation

As part of .NET 6 we updated the new LoggerMessage.Define overloads to use LogDefineOptions. (PR here and issue #50913)

Later in .NET 7, for supporting more arguments, we could add a new Define<T> API (where T is a delegate) that would take n arguments, log level, event ID, format string and LogDefineOptions to log message.

Theoretically we need an analyzer that makes sure the arguments of the new Define API are proper (ILogger etc.). The source generator would not be using the new Define (where T is delegate) API. (not source gen friendly).

Proposed API

Something like:

public static partial class LoggerMessage
{
+    public static void Define<T>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) where T : delegate {​ throw null; }​
}

T would be a delegate but an analyzer would need to make sure it takes ILogger, Exception, etc. System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, ..., Tn, System.Exception?>

TODO

cc: @davidfowl @eerhardt

Activity

  1. added
    api-suggestion
    on Jul 12, 2021
  2. ghost added
    untriaged
    on Jul 12, 2021
  3. removed
    untriaged
    on Jul 12, 2021
  4. added this to the 7.0.0 milestone on Jul 12, 2021
  5. self-assigned this
    on Jul 12, 2021
  6. modified the milestones: 7.0.0, 8.0.0 on Jun 14, 2022
  7. removed their assignment
    on Jan 9, 2023
  8. modified the milestones: 8.0.0, 9.0.0 on Jul 25, 2023
  9. modified the milestones: 9.0.0, Future on Nov 20, 2023
  10. abatishchev commented on Jun 1, 2024

    @abatishchev
    Contributor

    @tarekgh any update on this, please?

  11. tarekgh commented on Jun 2, 2024

    @tarekgh
    Member

    We couldn't get into this yet because we are occupied with other high-priority tasks.

  12. self-assigned this
    on Feb 4, 2026
  13. cincuranet commented on Feb 5, 2026

    @cincuranet
    Contributor

    Triage: The source generator we now have allows "unlimited" number of parameters and is superior to LoggerMessage.Define. It is not a 1:1 replacement, but we feel source generator solution is way better and should be used primarily.

    Example:

    static partial class LogMessages
    {
        [LoggerMessage(
            EventId = 3,
            Level = LogLevel.Information,
            Message = "Foo: {p1} {p2} {p3} {p4} {p5} {p6} {p7} {p8} {p9}")]
        public static partial void LogFoo(this ILogger logger, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9);
    }
  14. modified the milestones: Future, 11.0.0 on Feb 5, 2026
  15. locked and limited conversation to collaborators on Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-suggestionarea-Extensions-Logging

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions