-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LSG] LoggerMessage - Add diagnostic - Can't have the same template with different casing #52228
Comments
Tagging subscribers to this area: @maryamariyan Issue DetailsLoggerMessage 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);
|
ProposalThe 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:
And the following message format:
Code SampleThe 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);
}
"); |
It seems we generally want to allow message parameters and parameters in C# to be matched case-insensitively such that folks can use Pascal-casing in the message for example. However, when one does it in the case of parameters that have the same name but differ in case the result is ill-defined today. We can either do a diagnostic and disallow this (proposal) or we can change the source generator to first match case-sensitively and if that doesn't produce a match fall back to case-insensitive matching. We're leaning towards the latter. |
I looked at the details and I agree it is possible we fix the issue inside the source generator and not necessary adding the diagnostics. |
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:
Refer to: #51064 (comment)
LoggerMessage.Define
is also supported.Proposal
The proposed diagnostic descriptor would be:
With the following title:
And the following message format:
Code Sample
The diagnostic would be triggered for case such as the following ones:
The text was updated successfully, but these errors were encountered: