-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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] Logging Source Generator fails to detect event name uniqueness within a class scope #64667
Comments
Tagging subscribers to this area: @dotnet/area-extensions-logging Issue DetailsAs per design logging source generator provides a warning diagnostic when event ID is not unique within the scope of a class between log methods using
|
Hi @maryamariyan/@tarekgh, I'd like to take this one :) |
ProposalThe proposed diagnostic descriptor would be: public static DiagnosticDescriptor ShouldntReuseEventNames { get; } = new DiagnosticDescriptor(
id: "SYSLIB1025",
title: new LocalizableResourceString(nameof(SR.ShouldntReuseEventNamesTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.ShouldntReuseEventNamesMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
DiagnosticSeverity.Warning,
isEnabledByDefault: true); With the following title:
And the following message format:
Code SampleIReadOnlyList<Diagnostic> diagnostics = await RunGenerator(@"
partial class MyClass
{
[LoggerMessage(EventId = 0, EventName = ""MyEvent"", Level = LogLevel.Debug, Message = ""M1"")]
static partial void M1(ILogger logger);
[LoggerMessage(EventId = 1, EventName = ""MyEvent"", Level = LogLevel.Debug, Message = ""M1"")]
static partial void M2(ILogger logger);
}
"); |
@allantargino thanks for the proposal. I'll update the issue subject with it and we can take it to the design review. |
Thanks @tarekgh. Again, sorry - I did a mistake when copying the code sample from the tests. Would you please update it again? I really appreciated! |
Looks good as proposed |
As per design logging source generator provides a warning diagnostic when event ID is not unique within the scope of a class between log methods using
LoggerMessageAttribute
. It should also be able to set diagnostic message and detect when event name is being reused in the same scope.Proposal
The proposed diagnostic descriptor would be:
With the following title:
And the following message format:
Code Sample
The text was updated successfully, but these errors were encountered: