Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,20 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
}

bool hasMisconfiguredInput = false;
ImmutableArray<AttributeData>? boundAttrbutes = logMethodSymbol?.GetAttributes();
ImmutableArray<AttributeData>? boundAttributes = logMethodSymbol?.GetAttributes();

if (boundAttrbutes == null)
if (boundAttributes == null || boundAttributes!.Value.Length == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you need a ! here? You just checked it for null on the same line.

{
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down