我们自动将记录器注入到通用控制器类中。但是我们如何为泛型实用程序类派生一个记录器,该类的泛型类型与封闭的 Controller 不同?
public partial class GenericController<T> {
public GenericController(ILogger<T> logger)
{
MyUtility<DifferentClass> utlDifferent = new MyUtility<DifferentClass>( /*????*/ );
MyUtility<AnotherClass> utlAnother = new MyUtility<AnotherClass>( /*????*/ );
}
}
...
public class MyUtility<P> {
public MyUtility<P>(ILogger<P> logger) { }
}
有没有办法获取创建注入记录器实例的 LoggerFactory 并使用它来生成具有所有相同提供程序的新记录器?