Ninject logger using NLog

…衆ロ難τιáo~ 提交于 2019-12-03 10:53:36

I use the following:

.Bind<ILog>().ToMethod(p => LogManager.GetLogger(
                   p.Request.Target.Member.DeclaringType));

To have the logger with the name of the class. I'm using Log4net, but I think the idea can be applied to any log as well: in fact binding to a method open you to any solution in order to create the needed instance.

I use a ninject extension called Ninject.Extensions.Logging.NLog2, which can be found on NuGet or GitHub. It handles the binding of NLog, so you don't have to do anything else than just add it to your project and remove any bindings to NLog that you have right now.

As Felice mentioned you can use the same method, However for Nlog you need a little bit change which is :

.Bind<ILogger>().ToMethod(p => NLog.LogManager.GetCurrentClassLogger(
                   p.Request.Target.Member.DeclaringType));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!