title: How is NLog binded to ILogger with Ninject & Ninject.Extensions.Logging
body: <p>Hi I am trying to use NLog with an Web Api 2 application that uses Ninject for dependency injection.</p>
  <p>I have struggled to find any concrete info on how to do this so far I have installed the NuGet packages for NLog &amp; NLog.Configuration. So far what I have read suggests that theses packages should just work and take care of the binding for me.</p>
  <p>I set up the Nlog.config file and then I installed the Ninject.Extensions.Logging &amp; Ninject.Extensions.NLog4 packages.</p>
  <p>I'm trying to use NLog as follows</p>
  <pre><code>public class ErrorCheckController : ApiController
  {
      private readonly ILogger _logger;
  
      public ErrorCheckController(ILogger logger)
      {
          _logger = logger;
      }
  
      public IHttpActionResult Get(string version)
      {
          try
          {
              throw new Exception(&quot;Manually thrown exception&quot;);
          }
          catch (Exception ex)
          {
              _logger.Debug(ex);
          }
  
          return Ok();
      }
  }
  </code></pre>
  <p>In my NinjectWebCommon I have tried</p>
  <ol>
  <li>No Binding</li>
  <li>Binding with <code>kernel.Bind&lt;ILogger&gt;().To&lt;Logger&gt;();</code></li>
  <li>Binding with <code>kernel.Bind&lt;ILogger&gt;().ToMethod(lm =&gt; LogManager.GetLogger(&quot;MyLogger&quot;));</code> where MyLogger is the name of the target configuration</li>
  </ol>
  <p>When I do 1 &amp; 2 I get the error</p>
  <blockquote>
  <p>An error occurred when trying to create a controller of type 'ErrorCheckController'. Make sure that the controller has a parameterless public constructor.</p>
  </blockquote>
  <p>The 3rd option gets a Logger but it isn't configured using the NLog.config file</p>
  <p><strong>EDIT</strong>
  Here is my config file</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;nlog xmlns=&quot;http://www.nlog-project.org/schemas/NLog.xsd&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd&quot;
    autoReload=&quot;true&quot;
    throwExceptions=&quot;false&quot;&gt;
  
    &lt;targets&gt;
      &lt;target xsi:type=&quot;Database&quot; name=&quot;Ink3DPowderDbLogger&quot; connectionStringName=&quot;MyDbContext&quot;&gt;
        &lt;commandText&gt;
          INSERT INTO Log.ApiLog (
      Application,
      Logger,
      Logged,
      Level,
      Environment,
      Request,
      Message,
      BaseDir,
      Message,
      CallSite,
      CallSiteLn,
      Exception,
      EventProperties,
      StackTrace,
      ServerName,
      Port,
      Url,
      Https,
      ServerAddress,
      RemoteAddress,
      ) VALUES (
      @Application,
      @Logger,
      @Logged,
      @Level,
      @Environment,
      @Request,
      @BaseDir,
      @Message,
      @CallSite,
      @CallSiteLine,
      @Exception,
      @EventProperties,
      @StackTrace,
      @ServerName,
      @Port,
      @Url,
      @Https,
      @ServerAddress,
      @RemoteAddress,
      );
    &lt;/commandText&gt;
  
    &lt;parameter name=&quot;@application&quot; layout=&quot;${appsetting:name=AppName:default=Unknown}&quot; /&gt;
    &lt;parameter name=&quot;@logger&quot; layout=&quot;${logger}&quot; /&gt;
    &lt;parameter name=&quot;@logged&quot; layout=&quot;${date}&quot; /&gt;
    &lt;parameter name=&quot;@level&quot; layout=&quot;${level}&quot; /&gt;
    &lt;parameter name=&quot;@environment&quot; layout=&quot;${environment}&quot; /&gt;
    &lt;parameter name=&quot;@request&quot; layout=&quot;${asp-request}&quot; /&gt;
    &lt;parameter name=&quot;@basedir&quot; layout=&quot;${basedir}&quot; /&gt;
    &lt;parameter name=&quot;@message&quot; layout=&quot;${message}&quot; /&gt;
    &lt;parameter name=&quot;@callSite&quot; layout=&quot;${callsite}&quot; /&gt;
    &lt;parameter name=&quot;@callSiteLine&quot; layout=&quot;${callsite-linenumber}&quot; /&gt;
    &lt;parameter name=&quot;@exception&quot; layout=&quot;${exception:tostring}&quot; /&gt;
    &lt;parameter name=&quot;@eventproperties&quot; layout=&quot;${eventproperties:tostring}&quot; /&gt;
    &lt;parameter name=&quot;@stacktrace&quot; layout=&quot;${stacktrace:tostring}&quot; /&gt;
    &lt;parameter name=&quot;@serverName&quot; layout=&quot;${aspnet-request:serverVariable=SERVER_NAME}&quot; /&gt;
    &lt;parameter name=&quot;@port&quot; layout=&quot;${aspnet-request:serverVariable=SERVER_PORT}&quot; /&gt;
    &lt;parameter name=&quot;@url&quot; layout=&quot;${aspnet-request:serverVariable=HTTP_URL}&quot; /&gt;
    &lt;parameter name=&quot;@https&quot; layout=&quot;${when:inner=1:when='${aspnet-request:serverVariable=HTTPS}' == 'on'}${when:inner=0:when='${aspnet-request:serverVariable=HTTPS}' != 'on'}&quot; /&gt;
    &lt;parameter name=&quot;@serverAddress&quot; layout=&quot;${aspnet-request:serverVariable=LOCAL_ADDR}&quot; /&gt;
    &lt;parameter name=&quot;@remoteAddress&quot; layout=&quot;${aspnet-request:serverVariable=REMOTE_ADDR}:${aspnet-request:serverVariable=REMOTE_PORT}&quot; /&gt;
  
  &lt;/target&gt;
  
    &lt;/targets&gt;
  
    &lt;rules&gt;
      &lt;logger name=&quot;*&quot; minlevel=&quot;Info&quot; writeTo=&quot;Ink3DPowderDbLogger&quot; /&gt;
    &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>
  <p><strong>EDIT 2</strong>
  I Have changed my Get Method to</p>
  <pre><code>public IHttpActionResult Get(string version)
      {
          IKernel kernel = new StandardKernel();
          //var resolver = new NinjectDependencyResolver(kernel);
          //var logger = (ILogger) resolver.GetService(typeof(ILogger));
          var logger = kernel.Get&lt;ILogger&gt;();
  
          try
          {
              throw new Exception(&quot;Manually thrown exception&quot;);
          }
          catch (Exception ex)
          {
              //_logger.Debug(ex);
              logger.Debug(ex);
          }
  
          return Ok();
      }
  </code></pre>
  <p>This gives me an error</p>
  <blockquote>
  <p>No matching bindings are available, and the type is not self-bindable.</p>
  </blockquote>
  <p>Which sounds like nothing is getting binded to ILogger.</p>
  <p><strong>Edit 3</strong></p>
  <p>I was looking back over my config file and noticed that I had told NLog to fail silently. I turned this off and now I am getting proper errors. There seems to be an issue with my</p>
  <p>I get the errors</p>
  <blockquote>
  <p>Exception: Error when setting property 'Layout' on NLog.Targets.DatabaseParameterInfo</p>
  <p>Inner Exception: LayoutRenderer cannot be found: 'appsetting'</p>
  </blockquote>
  <p>I'm not too sure why this can't be found I'm using the same syntax that is in the documentation for appsetting</p>