-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed as not planned
Closed as not planned
Copy link
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-Logging
Milestone
Description
Today, using the LoggerMessage attribute, we can support mismatched orders, like:
[LoggerMessage(.., Message="message with foo: {foo}, and bar: {bar}"]
public void LogMethod(..., string bar, string foo)But this is not supported with LoggerMessage.Define. The best way to keep the feature set coherent here is to add an INFO diagnostic for LoggerMessage source generator, and mention that "the order from message template arguments did not match the expected order from the method arguments.
Proposal
The proposed diagnostic descriptor would be:
public static DiagnosticDescriptor ParametersOutOfOrder { get; } = new DiagnosticDescriptor(
id: "SYSLIB1026",
title: new LocalizableResourceString(nameof(SR.ParametersOutOfOrderTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.ParametersOutOfOrderMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
DiagnosticSeverity.Info,
isEnabledByDefault: true);With the following title:
Logging method contains parameters out of order provided in the message template
And the following message format:
Logging method '{0}' contains parameters out of order provided in the message template
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=""{a3},{a1},{a4},{a2}"")]
static partial void M1(ILogger logger, int a1, int a2, int a3, int a4);
[LoggerMessage(EventId = 1, Message=""{a2},{a3},{a1}"")]
static partial void M2(ILogger logger, int a1, LogLevel l, int a2, System.Exception e, int a3);
}
");Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-Logging