Skip to content

Source generation error in LoggerMessageAttribute in Microsoft.Extensions.Logging.Abstractions #91678

Description

@abrca

Description

Using 'params' keyword in method parameters "params object?[] args" in partial class under [LoggerMessage] attribute cause Compiler Error CS0758 - in generated code 'params' keyword is absent

Reproduction Steps

using Microsoft.Extensions.Logging;

internal static partial class LogMessages
{
    [LoggerMessage(Message = "Message: {message}, {args}", Level = LogLevel.Information)]
    internal static partial void MSG(this ILogger logger, string? message, params object?[] args);
}

Expected behavior

Compile

Actual behavior

in source-generated file LoggerMessage.g.cs, 'params' keyword is absent in method parameters "global::System.Object?[] args"

partial class LogMessages
{
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
    private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.String?, global::System.Object?[], global::System.Exception?> __MSGCallback =
        global::Microsoft.Extensions.Logging.LoggerMessage.Define<global::System.String?, global::System.Object?[]>(global::Microsoft.Extensions.Logging.LogLevel.Information, new global::Microsoft.Extensions.Logging.EventId(-1, nameof(MSG)), "Message: {message}, {args}", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true }); 

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "7.0.7.1805")]
    internal static partial void MSG(this global::Microsoft.Extensions.Logging.ILogger logger, global::System.String? message, global::System.Object?[] args)
    {
        if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Information))
        {
            __MSGCallback(logger, message, args, null);
        }
    }
}

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7.0
Windows 10 x64
Visual Studio Community 2022

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Extensions-LoggingenhancementProduct code improvement that does NOT require public API changes/additionsin-prThere is an active PR which will close this issue when it is mergedsource-generatorIndicates an issue with a source generator feature

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions