C#C
C#4y ago
Hugh

❔ Creating a class that takes a Logger for both the class and its base class

I'm trying to figure out the best way to use Loggers in my app.

All of the documentation that I've seen says to use Dependency Injection for this, and do something like:

public class MyClass
{
  private readonly ILogger<MyClass> _logger;
  public MyClass(ILogger<MyClass> logger)
  {
    _logger = logger;
  }
}


However, what I can't figure out is how I would do this when I have a
MyBaseClass
and a
MyClass
which is a subclass of
MyBaseClass
. I can't pass the same object from one constructor to the other.

Thanks
Was this page helpful?