Skip to content

Add LoggerMessage.Define overloads accepting up to 14 arguments. #50913

Closed

Description

@maryamariyan

We would like to have a LoggerMessage.Define() method that accepts up to 14 type args.

New API Proposal

public static partial class LoggerMessage
{
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​

where Microsoft.Extensions.Logging.LogOptions only has the one bool flag SkipEnabledCheck below:

namespace Microsoft.Extensions.Logging
{ 
    public class LogOptions
    {
        public bool SkipEnabledCheck { get; set; }
    }
}

The 6 new APIs below that were added in .NET 6 timeframe need to get updated as well.
It now makes sense to update to taking LogOptions instead of boolean skipEnabledCheck flag:

- public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
+ public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
- public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, System.Exception?> Define<T1, T2>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
+ public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, System.Exception?> Define<T1, T2>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
- public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, System.Exception?> Define<T1, T2, T3>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
+ public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, System.Exception?> Define<T1, T2, T3>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
- public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, System.Exception?> Define<T1, T2, T3, T4>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
+ public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, System.Exception?> Define<T1, T2, T3, T4>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
- public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.Exception?> Define<T1, T2, T3, T4, T5>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
+ public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.Exception?> Define<T1, T2, T3, T4, T5>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
- public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
+ public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​

More info for motive: #50334 (comment)

New proposal adds 10 new overloads. To support up to 16 arguments because that is what Action allows as well.

Previous API Proposal
public static partial class LoggerMessage
{
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString) { throw null; }
        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
}

Older issue (#35060) added up to 6 overlods for Define, this issue adds up to 16.

The reason to add up to 16 is because Action itself takes up to 16 parameters: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Action.cs#L24

Motivation

We've had requests to add more overloads in the past as well (e.g. #35060) so there is community interest in adding these APIs.

Also, the compile-time source generation for logging, allows support arbitrary number of parameters in a message template. But the runtime capabilities provided by LoggerMessage.Define APIs today is limited to only 6 parameters.

Adding the above APIs helps keep a more coherent range of logging feature support between compile-time and runtime in the framework library. This way for the most frequently hit user scenarios (up to 16 arguments) the compile time implementation can remain intact with runtime as well.

Additional Information

  • Link to logging generator: here
  • Link to generated baseline code samples using the logging generator: here

Follow up proposal - Support Dynamic Log Levels

As a follow up to the API proposal above, we could consider the APIs below as well to allow supporting dynamic log levels using LoggerMessage.Define.

Note: The compile-time source generator supports dynamic log levels as a feature.

public static partial class LoggerMessage
{
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, System.Exception?> Define(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, System.Exception?> Define<T1, T2>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, System.Exception?> Define<T1, T2, T3>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, System.Exception?> Define<T1, T2, T3, T4>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, System.Exception?> Define<T1, T2, T3, T4, T5>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, T8, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, T8, T9, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    public static System.Action<Microsoft.Extensions.Logging.ILogger, Microsoft.Extensions.Logging.LogLevel logLevel, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, System.Exception?> Define<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
}

Dynamic Log Levels - Usage in dotnet/aspnetcore:

https://github.com/dotnet/aspnetcore/blob/bbe65b8eaadcb6021f863a293fb57c46085db883/src/HealthChecks/HealthChecks/src/DefaultHealthCheckService.cs#L211-L227

Activity

  1. added
    api-ready-for-review
    on Apr 8, 2021
  2. ghost added
    untriaged
    on Apr 8, 2021
  3. added this to the 6.0.0 milestone on Apr 8, 2021
  4. removed
    untriaged
    on Apr 8, 2021
  5. added
    blocking
    on Apr 8, 2021
  6. bartonjs commented on Apr 9, 2021

    @bartonjs
    Member

    Video

    We think there's not a scenario for this, and we shouldn't add it until there is one.

  7. removed
    api-ready-for-review
    on Apr 9, 2021
  8. davidfowl commented on Apr 9, 2021

    @davidfowl
    Member

    Don't we want to add more than 6 though? Like 10?

  9. maryamariyan commented on Apr 29, 2021

    @maryamariyan
    ContributorAuthor

    Reopening this issue, with an update.

    Updated the issue description with the new proposal.
    The new proposal adds 10 new overloads.

  10. added
    api-ready-for-review
    on Apr 29, 2021
  11. GrabYourPitchforks commented on Apr 29, 2021

    @GrabYourPitchforks
    Member

    This issue now covers two topics: changing the signature of the previously-approved 6.0 APIs; and adding new overloads to cover additional generic parameters. I suspect the first one will sail through fairly smoothly.

    For the additional generic parameters, check Jeremy's comment at #50913 (comment). Is there new information that shows a need for 16 arguments? Something we wouldn't be able to get by adding, say, better low-allocation string interpolation overloads to the existing logging functions, which would allow them to scale up to arbitrary-arity inputs and would allow for short-circuiting when the given warning level is not enabled?

    Also keep in mind that if you're using Action<...>, you can't go beyond T14. You're already using two parameters for your ILogger and Exception args.

  12. changed the title [-]Add LoggerMessage.Define overloads accepting up to 16 arguments.[/-] [+]Add LoggerMessage.Define overloads accepting up to 14 arguments.[/+] on Apr 29, 2021
  13. maryamariyan commented on Apr 29, 2021

    @maryamariyan
    ContributorAuthor

    Also keep in mind that if you're using Action<...>, you can't go beyond T14. You're already using two parameters for your ILogger and Exception args.

    updated

  14. maryamariyan commented on Apr 29, 2021

    @maryamariyan
    ContributorAuthor

    For the additional generic parameters, check Jeremy's comment at #50913 (comment). Is there new information that shows a need for 16 arguments?

    One of the comments were about why we are adding two overloads per number of arguments (one with the skipEnabledCheck and one without). Using the new proposal we only add one overload per message template argument count.

    cc @geeknoid since he also pointed out that they have cases using more than 6 arguments.

  15. maryamariyan commented on Apr 29, 2021

    @maryamariyan
    ContributorAuthor

    Something we wouldn't be able to get by adding, say, better low-allocation string interpolation overloads to the existing logging functions, which would allow them to scale up to arbitrary-arity inputs and would allow for short-circuiting when the given warning level is not enabled?

    The string interpolation feature does not yet have a completed design for structured logging (scheduled within the .NET 6 timeframe). For Microsoft.Extensions.Logging we prototyped it partially in this design doc. There is also some discussion with Serilog owner on this too here.

    The goal here is to make sure the runtime capability keeps up with what we support with code gen. the string interpolation builder would still be code generated. So it probably would still make sense to add the above overloads regardless of where we end up with string interpolation feature.

  16. bartonjs commented on May 11, 2021

    @bartonjs
    Member

    The new overloads need more work, @davidfowl has concerns about the return type, and some explosion.

    The new LogOptions class should be LogDefineOptions

    namespace Microsoft.Extensions.Logging
    { 
        public class LogDefineOptions
        {
            public bool SkipEnabledCheck { get; set; }
        }
    }

    Updating the not-yet-released API:

    namespace Microsoft.Extensions.Logging
    { 
        public static partial class LoggerMessage
        {
    -        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
    +        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, System.Exception?> Define<T1>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    -        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, System.Exception?> Define<T1, T2>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
    +        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, System.Exception?> Define<T1, T2>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    -        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, System.Exception?> Define<T1, T2, T3>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
    +        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, System.Exception?> Define<T1, T2, T3>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    -        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, System.Exception?> Define<T1, T2, T3, T4>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
    +        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, System.Exception?> Define<T1, T2, T3, T4>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    -        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.Exception?> Define<T1, T2, T3, T4, T5>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
    +        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, System.Exception?> Define<T1, T2, T3, T4, T5>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
    -        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, bool skipEnabledCheck) { throw null; }
    +        public static System.Action<Microsoft.Extensions.Logging.ILogger, T1, T2, T3, T4, T5, T6, System.Exception?> Define<T1, T2, T3, T4, T5, T6>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, string formatString, Microsoft.Extensions.Logging.LogOptions options) {​ throw null; }​
        }
    }
  17. added
    api-needs-work
    and removed
    api-ready-for-review
    on May 11, 2021
  18. removed
    blocking
    on Jun 8, 2021
  19. maryamariyan commented on Jul 12, 2021

    @maryamariyan
    ContributorAuthor

    Closing this issue in favor of #55525. We already covered updating new .NET 6.0 overloads to use LogDefineOptions. The remainder of the work (support for more arguments) is scoped for .NET 7.0

  20. ghost locked as resolved and limited conversation to collaborators on Aug 11, 2021
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

    api-needs-workarea-Extensions-Logging

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions