Using Ninject to fill Log4Net Dependency

后端 未结 7 1242
天命终不由人
天命终不由人 2020-12-23 21:28

I use Ninject as a DI Container in my application. In order to loosely couple to my logging library, I use an interface like this:

public interface ILogger
         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 22:05

    Bind().ToMethod(x => LogManager.GetLogger(GetParentTypeName(x)))
                .InSingletonScope();
    

    You are currently binding in Singleton scope, so only one logger is created which will use the name of the first one created. Instead use InTransientScope()

提交回复
热议问题