使用NLOG Ninject记录仪 [英] Ninject logger using NLog
问题描述
我刚开始学习Ninject但遇到一个问题,在记录器。我现在有一个具有注入像这样的构造服务并记录器控制器:
I've just started learning Ninject but have come across a problem with the logger. I've currently got a controller that has a service and logger injected into the constructor like so:
public ToolsController(IToolsService toolsService, ILogger logger)
{
logger.Info("ToolsController Created");
this.toolsService = toolsService;
this.logger = logger;
}
在构造
的问题是在logger.Info线(例如)这似乎使用了错误的记录,因此,它打印出的记录器名称不正确。
The problem is on the logger.Info line (for example) in the constructor which seems to use the wrong logger, so the logger name it prints out is incorrect.
Tools.IGeocodeImporter: ToolsController Created
下面是它是如何设置,以获得日志名称:
Below is how it is setup to get the logger name:
kernel.Bind<ILogger>().To<Logger>().WithConstructorArgument("name", x => x.Request.ParentContext.Request.Service.FullName);
任何意见,将不胜感激。
Any advice would be appreciated.
推荐答案
我用ninject扩展名为Ninject.Extensions.Logging.NLog2,它可以在的的NuGet 或 GitHub上。它处理NLOG的结合,让你不必做任何事情不是仅仅把它添加到您的项目,并删除,你必须现在就NLOG任何绑定。
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.
这篇关于使用NLOG Ninject记录仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!