title: NLog is writing to file but not to database table
body: <p>This is my NLog.config file:</p>
  
  <pre><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="Off" internalLogFile="c:\temp\nlog-internal.log" &gt;
  
        &lt;variable name="myvar" value="myvalue"/&gt;
  
        &lt;targets&gt;
  
          &lt;target name="database" xsi:type="Database"
                  dbUserName="internwebuser"
                  dbProvider="System.Data.SqlClient"
                  connectionStringName="SECURE"
                  connectionString="Data Source=sqlservtest.starledger.com;Initial Catalog=SECURE;User ID=webuser;Password=password"
                  commandText="insert into dbo.tracelog (custom_message, excep_message, insertdate) 
                  values 
                  (@custom_message, @excep_message, @insertdate);" &gt;
  
  
            &lt;parameter name="@custom_message"     layout="${exception}" /&gt;
            &lt;parameter name="@excep_message"      layout="${exception:tostring}" /&gt;
            &lt;parameter name="@insertdate"         layout="${date}" /&gt;
  
  
          &lt;/target&gt;
  
  
          &lt;target name="file" xsi:type="File"
                  layout="${longdate} ${uppercase:${level}} ${callsite} from Line: ${callsite-linenumber} ${newline} 
      ${exception} ${newline}
      ${exception:tostring} ${newline}"
                  fileName="${basedir}/logs/${shortdate}-${level}.log" /&gt;
  
  
        &lt;/targets&gt;  
  
        &lt;rules&gt;
  
          &lt;logger name="*" minlevel="Debug" writeTo="file" /&gt;
          &lt;logger name="*" minlevel="Debug" writeTo="database" /&gt;
  
        &lt;/rules&gt;
      &lt;/nlog&gt;
  </code></pre>
  
  <p>And my controller looks something like this:</p>
  
  <pre><code>public class ReportController : Controller
  {
      private static Logger logger = LogManager.GetCurrentClassLogger();
  
      public ActionResult Index()
      {
          try 
          {
              &lt;!-- some statement --&gt;
          }
          catch (Exception e)
          {
              logger.Error(e);
          }
          return View();
     }
  }
  </code></pre>
  
  <p>This code writes perfectly into the file but the database table remains empty. Also, in my file, when I do it using <code>StreamWriter</code> and create a file instead of using NLog, the application writes 2/3 kinds of error into the file simultaneously. But NLog only writes the last error.</p>
  
  <p>For example:</p>
  
  <p>In case of <code>StreamWriter</code>, the errors are:</p>
  
  <pre><code>Exception Name:ExecuteReader requires an open and available Connection. The connection's current state is closed.
  
  Exception Name:Object reference not set to an instance of an object.
  </code></pre>
  
  <p>But In case of NLog, I only get:</p>
  
  <pre><code>Exception Name:Object reference not set to an instance of an object.
  and the first one is missed out.
  </code></pre>
  
  <p>My <code>StreamWriter</code> method looks like this:</p>
  
  <pre><code>DateTime today = DateTime.Now;
  
              string path = Directory.GetCurrentDirectory();
  
              string fileName = "error-log-" + today.Date.ToString("MM-dd-yyyy") + ".txt";
  
              var file = Path.Combine(path, fileName);
  
              StreamWriter log;
  
              if (!File.Exists(file))
              {
                  log = new StreamWriter(file);
              }
  
              else
              {
                  log = File.AppendText(file);
              }
  
              // Write to the file:
  
              log.WriteLine("Data Time:" + DateTime.Now);    
              log.WriteLine("Exception Name:" + sExceptionName);    
              log.WriteLine("Event Name:" + sEventName);    
              log.WriteLine("Error Line No.:" + nErrorLineNo);    
  
              // Close the stream:
  
              log.Close();
  </code></pre>
  
  <p>and I pass the method into the <code>catch</code> section of my controller.</p>
  
  <p>My main issue here is writing into the database table, although I'd appreciate help in writing all the errors too, using Nlog, instead of just the last one.</p>