-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes bad log method generation in certain cases. (#64311)
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
- Loading branch information
1 parent
93497f3
commit 24df302
Showing
6 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...xtensions.Logging.Generators.Tests/TestClasses/ExceptionTestExtensions.WithDiagnostics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses | ||
{ | ||
internal static partial class ExceptionTestExtensions | ||
{ | ||
#pragma warning disable SYSLIB1013 | ||
[LoggerMessage(EventId = 2, Level = LogLevel.Debug, Message = "M2 {arg1}: {ex}")] | ||
public static partial void M2(ILogger logger, string arg1, Exception ex); | ||
#pragma warning disable SYSLIB1013 | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ft.Extensions.Logging.Generators.Tests/TestClasses/LevelTestExtensions.WithDiagnostics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses | ||
{ | ||
internal static partial class LevelTestExtensions | ||
{ | ||
#pragma warning disable SYSLIB1002 | ||
[LoggerMessage(EventId = 12, Message = "M12 {level}")] | ||
public static partial void M12(ILogger logger, LogLevel level); | ||
#pragma warning restore SYSLIB1002 | ||
|
||
#pragma warning disable SYSLIB1018 | ||
[LoggerMessage(EventId = 13, Message = "M13 {logger}")] | ||
public static partial void M13(ILogger logger, LogLevel level); | ||
#pragma warning restore SYSLIB1018 | ||
} | ||
} |