diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs index 22ee4d13ef1caf..ac35a27938ad78 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs @@ -141,15 +141,20 @@ public IReadOnlyList GetLogClasses(IEnumerable? boundAttrbutes = logMethodSymbol?.GetAttributes(); + ImmutableArray? boundAttributes = logMethodSymbol?.GetAttributes(); - if (boundAttrbutes == null) + if (boundAttributes == null || boundAttributes!.Value.Length == 0) { continue; } - foreach (AttributeData attributeData in boundAttrbutes) + foreach (AttributeData attributeData in boundAttributes) { + if (attributeData.AttributeClass?.Equals(loggerMessageAttribute) != true) + { + continue; + } + // supports: [LoggerMessage(0, LogLevel.Warning, "custom message")] // supports: [LoggerMessage(eventId: 0, level: LogLevel.Warning, message: "custom message")] if (attributeData.ConstructorArguments.Any()) diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs index 05a7999c83c59d..4bb4271e2655c9 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs @@ -16,6 +16,21 @@ namespace Microsoft.Extensions.Logging.Generators.Tests [ActiveIssue("https://github.com/dotnet/runtime/issues/52062", TestPlatforms.Browser)] public class LoggerMessageGeneratorParserTests { + [Fact] + public async Task Valid_AdditionalAttributes() + { + Assert.Empty(await RunGenerator($@" + using System.Diagnostics.CodeAnalysis; + partial class C + {{ + [SuppressMessage(""CATEGORY1"", ""SOMEID1"")] + [LoggerMessage(EventId = 0, Level = LogLevel.Debug, Message = ""M1"")] + [SuppressMessage(""CATEGORY2"", ""SOMEID2"")] + static partial void M1(ILogger logger); + }} + ")); + } + [Fact] public async Task InvalidMethodName() {