title: Should NLog flush all queued messages in the AsyncTargetWrapper when Flush() is called?
body: <p>I want to shut down my application and write any pending log messages. So I call <code>LogManager.Flush()</code> during my shutdown process. However, I don't see all the messages written out. Instead, if I wait for a few seconds (using <code>Thread.Sleep()</code>) I see the messages.</p>
  
  <p>After examining <a href="https://github.com/jkowalski/NLog/blob/master/src/NLog/Targets/Wrappers/AsyncTargetWrapper.cs" rel="noreferrer">NLog's code on GitHUB</a>, I find the <code>AsyncTargetWrapper.FlushAsync()</code> method is only scheduling the lazy writer thread to write all pending messages on the next batch. It is not writing log messages synchronously.</p>
  
  <p>Is this the expected behaviour? I'm expecting <code>LogManager.Flush()</code> to be synchronous, ie: to block until all pending messages are written (or the timeout is exceeded).</p>
  
  <hr>
  
  <p>Code I use on shutdown:</p>
  
  <pre><code>LogManager.Flush(ex =&gt; { }, TimeSpan.FromSeconds(15));
  </code></pre>
  
  <p>And then the code to initialise Nlog (this is a Silverlight app, so I'm not using any config files).</p>
  
  <pre><code>    public static void InitialiseNLog(LogLevel forLevel)
      {
          var config = new LoggingConfiguration();
  
          // Add targets.
          // We need an async target wrapping a custom web service call back to the server.
          var serverTarget = new RemoteServiceTarget();
          var asyncWrapper = new AsyncTargetWrapper(serverTarget, 10000, AsyncTargetWrapperOverflowAction.Discard);
          asyncWrapper.TimeToSleepBetweenBatches = (int)TimeSpan.FromSeconds(2).TotalMilliseconds;
          asyncWrapper.BatchSize = 200;
  
          // Add rules.
          var rule = new LoggingRule("Company.Application.SilverlightApp.*", forLevel, asyncWrapper);
          config.LoggingRules.Add(rule);
  
          // Activate the configuration.
          LogManager.Configuration = config;
          LogManager.GlobalThreshold = forLevel;
      }
  </code></pre>