title: Nlog: Having problems logging exception details to database.
body: <p>My nlog config file is </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"&gt;
  
    &lt;!-- 
    See https://github.com/nlog/nlog/wiki/Configuration-file 
    for information on customizing logging rules and outputs.
     --&gt;
    &lt;targets&gt;
      &lt;!-- add your targets here --&gt;
  
      &lt;!--
      &lt;target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
              layout="${longdate} ${uppercase:${level}} ${message}" /&gt;           
  
      --&gt;
      &lt;target name="database" xsi:type="Database" keepConnection="true" useTransactions="true"
            dbProvider="System.Data.SqlClient"
              connectionString="Server=******\SQLEXPRESS;User Id=sa;Password=****;Database=*****_dev;MultipleActiveResultSets=true;"           
             commandText="INSERT INTO Logs(EventDateTime, EventLevel, UserName, MachineName, EventMessage, ErrorSource, ErrorClass, ErrorMethod, ErrorMessage, InnerErrorMessage) VALUES (@EventDateTime, @EventLevel, 'SE', @MachineName, @EventMessage, @ErrorSource, @ErrorClass, @ErrorMethod, @ErrorMessage, @InnerErrorMessage)"&gt;
        &lt;!-- parameters for the command --&gt;
        &lt;parameter name="@EventDateTime" layout="${date:s}" /&gt;
        &lt;parameter name="@EventLevel" layout="${level}" /&gt;     
        &lt;parameter name="@MachineName" layout="${machinename}" /&gt;      
        &lt;parameter name="@ErrorSource" layout="${exception:format=ToString,StackTrace}" /&gt;
        &lt;parameter name="@EventMessage" layout="${message}" /&gt;
        &lt;parameter name="@ErrorClass" layout="${event-context:item=error-method}" /&gt;
        &lt;parameter name="@ErrorMethod" layout="${event-context:item=error-method}" /&gt;
        &lt;parameter name="@ErrorMessage" layout="${event-context:item=error-message}" /&gt;
        &lt;parameter name="@InnerErrorMessage" layout="${event-context:item=inner-error-message}" /&gt;
      &lt;/target&gt;
    &lt;/targets&gt;
  
    &lt;rules&gt;
      &lt;!-- add your logging rules here --&gt;
  
  
      &lt;logger name="*" minlevel="Trace" writeTo="database" /&gt;
  
    &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>
  
  <p>and it is only inserting EventDateTime, EventLevel, UserName, MachineName and EventMessage but it is leaving the exception and event context fields blank ?</p>
  
  <p>I am clearly missing something with exception stuff and I could not figure out what it is.</p>
  
  <p>Please see my C# code below.</p>
  
  <pre><code> public void Log(Exception ex)
       {
               LogEventInfo ev = new LogEventInfo(LogLevel.Error, logger.Name ,ex.Message);
               ev.Exception = ex;               
               logger.Error(ev);             
       }
  </code></pre>
  
  <p>Please provide suggestions</p>