title: NLog async target database connection exceptions - how to get them?
body: <p>Can anyone help me with a situation where NLog is logging into a database using <code>AsyncTargetWrapper</code> and there is a connection problem? How can I obtain/intercept those exceptions (since async targets don't throw exceptions)? It seems to be a pretty common scenario so I find it hard to believe that <code>InternalLogger</code> is the only option. Here's an example project (requires NLog nuget package installed):</p>
  
  <pre><code>using System;
  using System.Threading;
  using NLog;
  using NLog.Common;
  using NLog.Config;
  using NLog.Targets;
  using NLog.Targets.Wrappers;
  
  class Program
  {
      static void Main(string[] args)
      {
          LogManager.ThrowExceptions = true;
          InternalLogger.LogToConsole = true;
          InternalLogger.LogLevel = LogLevel.Error;
  
          var conf = new LoggingConfiguration();
          var target = new DatabaseTarget
          {
              ConnectionString =
                  "Server=BAD_SERVER;Database=foo;",
              CommandText = "INSERT INTO logs(message) VALUES ('bar')"
          };
  
          var asyncTarget = new AsyncTargetWrapper(target);
          var rule = new LoggingRule("*", LogLevel.Trace, asyncTarget);
          conf.LoggingRules.Add(rule);
  
          LogManager.Configuration = conf;
  
          Logger logger = LogManager.GetLogger("Example");
          logger.Info("Message"); // doesn't throw an exception
  
          Thread.Sleep(16000);
  
          Console.WriteLine("\nDone");
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>So the app can't connect to the server (invalid server name in connection string). After some default (hidden in NLog's guts?) connection timeout is hit, an exception is printed to the console by <code>InternalLogger</code>:</p>
  
  <pre><code>2016-01-20 16:39:36.8466 Error Error when writing to database System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
  </code></pre>
  
  <p>Now, I know I can set <code>InternalLogger.LogFile()</code> but I have to use this in a Web service hosted on Azure Web Apps and it doesn't create any file when I try that (I have to use relative path, which works locally in a console app but not after deployment to Azure).</p>
  
  <p>How one deals with connection exceptions when using async NLog logger?</p>