Using Ninject to fill Log4Net Dependency

后端 未结 7 1208
天命终不由人
天命终不由人 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:24

    The Ninject.Extension.Logging extension already provides all you are implementing yourself. Including support for log4net, NLog and NLog2.

    https://github.com/ninject/ninject.extensions.logging


    Also you want to use the following as logger type:

    context.Request.ParentRequest.ParentRequest.Target.Member.DeclaringType
    

    Otherwise you will get the logger for the service type instead of the implementation type.

    0 讨论(0)
提交回复
热议问题