Repository navigation
Description
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.");- 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]
- 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
dotnet-policy-service commentedon Apr 29, 2024
Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.
ericstj commentedon Aug 6, 2024
@reyang @tarekgh is this behavior change a must-have for 9.0, or could we move this out?
tarekgh commentedon Aug 6, 2024
I moved this to .NET 10.
cincuranet commentedon Feb 10, 2026
Triage: Producing 5 warnings is indeed weird. We should produce only one per given log message.
Don't show SYSLIB1015 when no template given (#131878)