== How to fix it

When the logger name is defined by a generic type parameter:

[source,csharp]
----
class EnclosingType
{
    private readonly ILogger logger;

    public EnclosingType(ILoggerFactory loggerFactory)
    {
        logger = loggerFactory.CreateLogger<AnotherType>();   // Noncompliant
        logger = loggerFactory.CreateLogger<EnclosingType>(); // Compliant
    }
}
----

When the logger name is defined by an input parameter of type `Type`:

[source,csharp]
----
class EnclosingType
{
    private readonly ILogger logger;

    public EnclosingType(ILoggerFactory loggerFactory)
    {
        logger = loggerFactory.CreateLogger(typeof(AnotherType));   // Noncompliant
        logger = loggerFactory.CreateLogger(typeof(EnclosingType)); // Compliant
        logger = loggerFactory.CreateLogger(GetType());             // Compliant
    }
}
----

When the logger name is a string, derived from a `Type`:

[source,csharp]
----
class EnclosingType
{
    private readonly ILogger logger;

    public EnclosingType(ILoggerFactory loggerFactory)
    {
        logger = loggerFactory.CreateLogger(typeof(AnotherType).Name);       // Noncompliant        
        logger = loggerFactory.CreateLogger(typeof(AnotherType).FullName);   // Noncompliant
        logger = loggerFactory.CreateLogger(nameof(AnotherType));            // Noncompliant
        // Fix by referring to the right type
        logger = loggerFactory.CreateLogger(typeof(EnclosingType).Name);     // Compliant
        logger = loggerFactory.CreateLogger(typeof(EnclosingType).FullName); // Compliant
        logger = loggerFactory.CreateLogger(nameof(EnclosingType));          // Compliant
        // or by retrieving the right type dynamically
        logger = loggerFactory.CreateLogger(GetType().FullName);             // Compliant
    }
}
----

