You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Logging Source Generator causes errors and warnings for messages using formatting specifiers #62572
When using formatting specifiers in log message templates like {@Data} or {$Data}, the logging source generator logs warnings and errors but should compile fine.
Reproduction Steps
usingMicrosoft.Extensions.Logging;publicstaticpartialclassExtensions{publicstaticvoidLogPerson(thisILoggerlogger,Personperson)=>logger.LogInformation("The person is {@Person}",person);[LoggerMessage(Level=LogLevel.Information,Message="The person is {@Person}")]publicstaticpartialvoidOtherLogPerson(thisILoggerlogger,Personperson);}publicrecordPerson(stringFirstName,stringLastName){publicoverridestringToString()=>$"Person({FirstName}{LastName})";}
Depending on the formatter used (NLog/Serilog/inbox console) there should be a difference when using {@Person} vs {Person} (in some cases {$Person})
Expected behavior
The code should compile without warnings or errors.
Actual behavior
SYSLIB1015 and SYSLIB1014 diagnostics and CS0119 error:
C:\demos\LoggingGeneratorFormatErrorExample\Class1.cs(9,75): warning SYSLIB1015: Argument 'person' is not referenced from the logging message [C:\demos\LoggingGeneratorFormatErrorExample\LoggingGeneratorErrorExample.csproj]
C:\demos\LoggingGeneratorFormatErrorExample\Class1.cs(8,6): error SYSLIB1014: Template '@Person' is not provided as argument to the logging method [C:\demos\LoggingGeneratorFormatErrorExample\LoggingGeneratorErrorExample.csproj]
C:\demos\LoggingGeneratorFormatErrorExample\Microsoft.Extensions.Logging.Generators\Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator\LoggerMessage.g.cs(20,41): error CS0119: 'Person' is a type, which is not valid in the given context [C:\demos\LoggingGeneratorFormatErrorExample\LoggingGeneratorErrorExample.csproj]
Configuration
.NET 6 class library with 6.0.0 Microsoft.Extensions.Logging nuget pacakge
Activity
martincostello commentedon Dec 9, 2021
Partial dupe of #60968 for usage of
@(I didn't encounter the$case).