Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.2 KB

File metadata and controls

45 lines (32 loc) · 1.2 KB

MA0180 - ILogger type parameter should match containing type

Sources: ILoggerParameterTypeShouldMatchContainingTypeAnalyzer.cs, ILoggerParameterTypeShouldMatchContainingTypeFixer.cs

Description

When using ILogger<T> in a class constructor, the type parameter should match the containing class. This helps ensure proper categorization of log messages and makes it easier to filter logs by component.

Non-compliant code

using Microsoft.Extensions.Logging;

class A(ILogger<B> logger)
{
}

class B
{
}

Compliant code

using Microsoft.Extensions.Logging;

class A(ILogger<A> logger)
{
}

class B
{
}

Configuration

This rule is disabled by default. You can enable it by setting the severity in your .editorconfig file:

# MA0180: ILogger type parameter should match containing type
dotnet_diagnostic.MA0180.severity = warning