Sources: ILoggerParameterTypeShouldMatchContainingTypeAnalyzer.cs, ILoggerParameterTypeShouldMatchContainingTypeFixer.cs
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.
using Microsoft.Extensions.Logging;
class A(ILogger<B> logger)
{
}
class B
{
}using Microsoft.Extensions.Logging;
class A(ILogger<A> logger)
{
}
class B
{
}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