title: Logging to NLog in Hangfire.io
body: <p>I am currently using Hangfire to run some jobs in a windows service.  The jobs are fired from a WebAPI.</p>
  
  <p>My system is currently working fine when all jobs succeed, but I am getting no logging for when exceptions occur.  Has anyone got any experience in using a custom logger to receive messages from Hangfire?</p>
  
  <p>My logger is a basic NLog interface:</p>
  
  <pre><code>public class Logger : ILogger
  {
      public readonly NLog.Logger logger;
  
      public Logger(string name)
      {
          if (LogManager.Configuration == null)
          {
              FallbackInitialisation();
          }
  
          logger = LogManager.GetLogger(name);
      }
  
      public Trace(string message)
      //etc.
  }
  </code></pre>
  
  <p>I am configuring my Hangfire job server in my windows service like so:</p>
  
  <pre><code>SqlServerStorage storage = new SqlServerStorage("myConnectionString");
  BackgroundJobServerOptions options = new BackgroundJobServerOptions();
  m_server = new BackgroundJobServer(options, storage);
  GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 });
  </code></pre>
  
  <p>Based on the <a href="http://docs.hangfire.io/en/latest/deployment-to-production/adding-logging.html" rel="nofollow">hangfire documentation</a>, I simply tried following it by adding the required references, and adding the following after my job server setup, however there were still no logs produced:</p>
  
  <pre><code>var properties = new NameValueCollection();
  properties["configType"] = "INLINE";
  LogManager.Adapter = new NLogLoggerFactoryAdapter(properties);
  </code></pre>
  
  <p>I am simply simulating an exception by <code>throw new Exception()</code> in the method called by the job. The job is created in the webApi call like so:</p>
  
  <pre><code>[HttpGet]
  public void TestStartJob()
  {
      m_logger.Trace("TestStartJob");
      BackgroundJob.Enqueue(() =&gt; m_service.TestStartJob());
  }
  </code></pre>
  
  <p>What I am looking for, is if anyone has any experience in getting logging properly configured for use with Hangfire.</p>