Skip to content

Strange behavior while using compile-time logging source generation without message template #101687

Closed

Description

@reyang

Description

When using compile-time logging source generation from Micrososft.Extensions.Logging.Abstraction version 8.0 and the message template provided:

internal static partial class LoggerExtensions
{
    [LoggerMessage(LogLevel.Critical)]
    public static partial void FoodRecallNotice(
        this ILogger logger,
        string brandName,
        string productDescription,
        string productType,
        string recallReasonDescription,
        string companyName);
}

logger.FoodRecallNotice(
    brandName: "Contoso",
    productDescription: "Salads",
    productType: "Food & Beverages",
    recallReasonDescription: "due to a possible health risk from Listeria monocytogenes",
    companyName: "Contoso Fresh Vegetables, Inc.");
  1. The warning message seems to be confusing:
D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\Program.cs(39,16): warning SYSLIB1015: Argument 'brandNa
me' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/sysl
ib1015) [D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\getting-started-console.csproj::TargetFramework
=net8.0]
D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\Program.cs(40,16): warning SYSLIB1015: Argument 'product
Description' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnos
tics/syslib1015) [D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\getting-started-console.csproj::Target
Framework=net8.0]
D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\Program.cs(41,16): warning SYSLIB1015: Argument 'product
Type' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/sy
slib1015) [D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\getting-started-console.csproj::TargetFramewo
rk=net8.0]
D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\Program.cs(42,16): warning SYSLIB1015: Argument 'recallR
easonDescription' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-di
agnostics/syslib1015) [D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\getting-started-console.csproj::T
argetFramework=net8.0]
D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\Program.cs(43,16): warning SYSLIB1015: Argument 'company
Name' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/sy
slib1015) [D:\repo\opentelemetry-dotnet\docs\logs\getting-started-console\getting-started-console.csproj::TargetFramewo
rk=net8.0]
  1. The console output doesn't seem to be helpful:
crit: Program[1338249384]

Reproduction Steps

Check open-telemetry/opentelemetry-dotnet#5553 (comment)

Expected behavior

Instead of giving 5 warnings, it'll be better to provide 1 INFO level message (e.g. "The message template is not specified; a default template will be generated"). In addition, the console logger provider should output all the key-value pairs.

Alternatively, aligning with Microsoft.Extensions.Logging.Abstraction, as described in open-telemetry/opentelemetry-dotnet#5553 (comment).

Actual behavior

User gets 5 warnings, which normally break the build due to "treat warnings as errors" setting.
The console output only shows crit: Program[1338249384] without any key-value pairs.

Regression?

No

Known Workarounds

Provide a message template with all the key-value pairs.

Configuration

No response

Other information

No response

Activity

  1. dotnet-policy-service commented on Apr 29, 2024

    @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.

  2. added this to the 9.0.0 milestone on Apr 29, 2024
  3. added
    source-generatorIndicates an issue with a source generator feature
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Apr 29, 2024
  4. ericstj commented on Aug 6, 2024

    @ericstj
    Member

    @reyang @tarekgh is this behavior change a must-have for 9.0, or could we move this out?

  5. modified the milestones: 9.0.0, 10.0.0 on Aug 6, 2024
  6. tarekgh commented on Aug 6, 2024

    @tarekgh
    Member

    I moved this to .NET 10.

  7. modified the milestones: 10.0.0, Future on Jul 26, 2025
  8. cincuranet commented on Feb 10, 2026

    @cincuranet
    Contributor

    Triage: Producing 5 warnings is indeed weird. We should produce only one per given log message.

  9. self-assigned this
    on Jun 29, 2026
  10. modified the milestones: Future, 12.0.0 on Aug 21, 2026
  11. added a commit that references this issue on Sep 2, 2026
    0d845c7
  12. locked and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions