I have a base class that does some work, including logging. I have an ILogger dependency injected into the constructor
public abstract class BaseClassExample
{
protected readonly ILogger<BaseClassExample> logger;
public class BaseClassExample(ILogger<BaseClassExample> logger)
{
this.logger = logger;
}
}
And I want to have classes implement BaseClassExample, and do their own work too, also including logging.
public class DerivedClass : BaseClassExample
{
protected readonly ILogger<DerivedClass> logger;
public class BaseClassExample(ILogger<DerivedClass> logger)
{
this.logger = logger;
}
}
Is this the right way of doing things? Am I supposed to get the implementing class's type for logging for the base class? Should I have a separate instance of a logger (with the DerivedClass's type) or try and use the same one as the base class?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…