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
LoggerMessageAttribute generated source does not respect escaped characters and does not compile #56203
The source code generated for the following log method does not compile.
[LoggerMessage(EventId=1,Level=LogLevel.Debug,Message="This is a log message: \"{Value1}\"")]publicstaticpartialvoidSomeEvent(ILoggerlogger,stringvalue1,stringvalue2);
The fact that this log method includes parameters that are not encoded into Message forces a custom log state type to be generated, with the following code:
publicoverridestringToString(){varValue1=this._value1;return$"This is a log message: "{Value1}"";
}
Configuration
Running .NET SDK 6.0.100-preview.6.21355.2 with version 6.0.0-preview.6.21352.12 of Microsoft.Extensions.Logging.Abstractions.
[LoggerMessage(EventId=1,Message="This is a log message: {Value1} {Value2}")]publicstaticpartialvoidSomeEvent(ILoggerlogger,LogLevellogLevel,stringvalue1,stringvalue2);
but for the snippet below with escaped characters, the generated code has issues:
[LoggerMessage(EventId=1,Message="This is a log message: \"{Value1}\"\"{Value2}\"")]publicstaticpartialvoidSomeEvent(ILoggerlogger,LogLevellogLevel,stringvalue1,stringvalue2);
ghost added
in-prThere is an active PR which will close this issue when it is merged
Activity
maryamariyan commentedon Jul 26, 2021
for your sample code, in the errors list you should see:
which points to what needs to get fixed.
maryamariyan commentedon Jul 26, 2021
Thanks for the report, here's another repro code:
The code below works fine:
but for the snippet below with escaped characters, the generated code has issues: