Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 529 Bytes

ContextualLoggerProblem.md

File metadata and controls

49 lines (39 loc) · 529 Bytes

Incorrect type is used for contextual logger

Noncompliant Code Examples:

class A
{
    private static readonly ILogger Logger = Logger.ForContext<B>();
}

class B {} 
class A
{
	ILogger<B> _log;
	
	public A(ILogger<B> log)
	{
		_log = log;
	}
}

class B { } 

Compliant Solution:

class A
{
    private static readonly ILogger Logger = Logger.ForContext<A>();
}

class B {} 
class A
{
	ILogger<A> _log;
	
	public A(ILogger<A> log)
	{
		_log = log;
	}
}

class B {}