From 1d77d983b193d24509fa018aefea20eb05105bbc Mon Sep 17 00:00:00 2001 From: Maryam Ariyan Date: Tue, 25 Jan 2022 19:26:13 -0800 Subject: [PATCH] Fixes bad log method generation in certain cases. In certain cases when developer by mistake places ILogger, Exception, or LogLevel in the message template, the code generator will produce the expected warning and makes sure the code will indeed compile and run correctly. Prior to this fix, the code generator would fail to compile with when either of ILogger, Exception or LogLevel were placed in message template incorrectly. Fixes #64310 --- .../gen/LoggerMessageGenerator.Parser.cs | 6 +++++- .../LoggerMessageGeneratedCodeTests.cs | 21 +++++++++++++++++++ .../LoggerMessageGeneratorEmitterTests.cs | 2 +- .../LoggerMessageGeneratorParserTests.cs | 12 +++++++++-- ...ExceptionTestExtensions.WithDiagnostics.cs | 15 +++++++++++++ .../LevelTestExtensions.WithDiagnostics.cs | 18 ++++++++++++++++ 6 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/TestClasses/ExceptionTestExtensions.WithDiagnostics.cs create mode 100644 src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/TestClasses/LevelTestExtensions.WithDiagnostics.cs diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs index f33f506a213787..a645479b20b14a 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs @@ -341,17 +341,21 @@ public IReadOnlyList GetLogClasses(IEnumerable GetLogClasses(IEnumerable