-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-Extensions-Loggingin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
LoggerMessage supports case insensitive parameters. But we need to add a diagnostic when different casing of the same parameter is specified in the same message template like in the below sample:
[LoggerMessage(EventId = 0, Level = LogLevel.Debug, Message = ""M1 {p1} {P1}"")]
public static partial void M1(ILogger logger, int p1, int P1);Refer to: #51064 (comment)
- Note: case insensitive support against on
LoggerMessage.Defineis also supported.
Proposal
The proposed diagnostic descriptor would be:
public static DiagnosticDescriptor InconsistentTemplateCasing { get; } = new DiagnosticDescriptor(
id: "SYSLIB1021",
title: new LocalizableResourceString(nameof(SR.InconsistentTemplateCasingTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.InconsistentTemplateCasingMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
DiagnosticSeverity.Error,
isEnabledByDefault: true);With the following title:
Logging method have the same template with different casing
And the following message format:
Logging method '{0}' have the same template with different casing
Note:
SYSLIB1021diagnostic descriptor is already merged onmain, but it is not being triggered.
Code Sample
The diagnostic would be triggered for case such as the following ones:
IReadOnlyList<Diagnostic> diagnostics = await RunGenerator(@"
partial class C
{
[LoggerMessage(EventId = 0, Level = LogLevel.Debug, Message = ""M1 {par1} {PAr1} {a}"")]
static partial void M1(ILogger logger, int par1, int a);
}
");Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-Extensions-Loggingin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged