title: NLog not logging (Windows Service)
body: <p>I have a windows service that I am converting from my own logging to NLog.  I have used NLog in a previous windows service application and felt that I knew what I was doing. But it isn't logging :(</p>
  
  <p>I have the following NLog Configuration:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
        autoReload="true"
        throwExceptions="false"
        internalLogLevel="On" internalLogFile="c:\temp\nlog-internal.log" &gt;
  
    &lt;variable name="DebugInfoLayout" value="[${date:format=MM/dd/yyyy h\:mm\:ss tt}] [${gdc:item=location}]  |  ${level}  |  ${message}" /&gt;
    &lt;variable name="InfoLayout" value="[${date:format=MM/dd/yyyy h\:mm\:ss tt}] ${gdc:item=SoftwareName} Version ${gdc:item=SoftwareVersion}  -  ${message}" /&gt;
    &lt;variable name="LogLayout" value="[${date:format=MM/dd/yyyy h\:mm\:ss tt}] ${message}" /&gt;
    &lt;variable name="logDir" value="${basedir}/LogFiles" /&gt;
    &lt;variable name="ArchiveDir" value="${basedir}/LogFiles/Archive" /&gt;
  
    &lt;targets async="true"&gt;
      &lt;target name="Errors" xsi:type="File" fileName="${logDir}/errors.log" layout="${LogLayout}" keepFileOpen="false" archiveFileName="${ArchiveDir}/errors_${shortdate}.{##}.log" archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30" archiveOldFileOnStartup="true" /&gt;
      &lt;target name="Info" xsi:type="File" fileName="${logDir}/info.log" layout="${InfoLayout}"  keepFileOpen="false" archiveFileName="${ArchiveDir}/info_${shortdate}.{##}.log" archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30"/&gt;
      &lt;target name="Debug" xsi:type="File" fileName="${logDir}/debug.log" layout="${DebugInfoLayout}"  keepFileOpen="false" archiveFileName="${ArchiveDir}/debug_${shortdate}.{##}.log" archiveNumbering="Sequence" archiveEvery="Day" maxArchiveFiles="30" /&gt;  
    &lt;/targets&gt;
  
    &lt;rules&gt;
      &lt;logger name="Errors" minlevel="Trace" maxlevel="Fatal" writeTo="Errors" /&gt;
      &lt;logger name="Info" minlevel="Trace" maxlevel="Warn" writeTo="Info" /&gt;
      &lt;logger name="Debug" minlevel="Trace" maxlevel="Fatal" writeTo="Debug" /&gt;
    &lt;/rules&gt;
  &lt;/nlog&gt;    
  </code></pre>
  
  <p>To me, this looks correct.  And it is the same as in my other application.  From the code perspective, I have this in my service.vb file:</p>
  
  <pre><code>'NLog Instances
  Dim errorLogger As NLog.Logger = NLog.LogManager.GetLogger("Errors")
  Dim infoLogger As NLog.Logger = NLog.LogManager.GetLogger("Info")
  Dim debugLogger As NLog.Logger = NLog.LogManager.GetLogger("Debug")
  </code></pre>
  
  <p>Then lower in the subroutines:</p>
  
  <pre><code>    Try
      Catch ex As Exception
          WritetoNLog(errorlogger, NLog.LogLevel.Error, System.Reflection.MethodInfo.GetCurrentMethod.Name, ex.Message)
          WritetoNLog(errorlogger, NLog.LogLevel.Error, System.Reflection.MethodInfo.GetCurrentMethod.Name, ex.InnerException.ToString)
      End Try
  </code></pre>
  
  <p>And then for that simple routine:</p>
  
  <pre><code>Public Sub WritetoNLog(ByRef logger As NLog.Logger, ByVal nlogtype As NLog.LogLevel, ByVal location As String, message As String)
      NLog.GlobalDiagnosticsContext.Set("location", String.Format("{0,-35}", location))
  
      Select Case nlogtype
          Case NLog.LogLevel.Trace
              logger.Trace(message)
          Case NLog.LogLevel.Fatal
              logger.Fatal(message)
          Case NLog.LogLevel.Info
              logger.Info(message)
          Case NLog.LogLevel.Debug
              logger.Debug(message)
          Case NLog.LogLevel.Error
              logger.Error(message)
          Case NLog.LogLevel.Warn
              logger.Warn(message)
      End Select
  
      NLog.LogManager.Flush()
  
  End Sub
  </code></pre>