Add Nlog, Ninject.Extensions.Logging and
Ninject.Extensions.Logging.NLog to your project.
Add something like this to your app.config:
<configSections>4
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="
http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console"
layout="${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger}
${message} ${exception:format=message,type,stacktrace}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="console" />
</rules>
</nlog>
Inject ILogger into your classes:
using Ninject.Extensions.Logging;
public class HelloWorld
{
private ILogger _log;
public HelloWorld(ILogger log)
{
_log = log;
}
public void SayHello()
{
_log.Info("Hello, World!");
}
}
ILogger is injected automatically by the Ninject kernel when the
object is created:
var kernel = new StandardKernel();
var hello = kernel.Get<HelloWorld>();
hello.SayHello();
Hope that helps.
T.