title: How do I log a custom field in NLog to database?
body: <p>I currently use NLog on a lot of projects. On some, I log to a database. </p>
  
  <p>Here is what I would like to do:</p>
  
  <pre><code>CREATE TABLE [dbo].[NLogEntries](
    [Id] [bigint] IDENTITY(1,1) NOT NULL,
    [Origin] [nvarchar](100) NOT NULL,
    [LogLevel] [nvarchar](20) NOT NULL,
    [Message] [nvarchar](3600) NOT NULL,
    [CreatedOn] [datetime] NOT NULL,
    [OrderId] [int] NULL --Custom field!
  )
  </code></pre>
  
  <p>And NLog.config with this target:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;target type="Database" name="database" connectionstring="Server=localhost;Database=NLog;Trusted_Connection=True;"&gt;
    &lt;commandText&gt;
      INSERT INTO NLogEntries ([Origin], [Message], [LogLevel],[CreatedOn],[OrderId]) VALUES (@Origin,@Message,@LogLevel,@Date, @OrderId);
    &lt;/commandText&gt;
    &lt;parameter name="@Date" layout="${date}"/&gt;
    &lt;parameter name="@Origin" layout="${callsite}"/&gt;
    &lt;parameter name="@LogLevel" layout="${level}"/&gt;
    &lt;parameter name="@message" layout="${message}"/&gt;
    &lt;parameter name="@OrderId" layout="${orderId}"/&gt; &lt;!-- custom field! --&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>And then log something like this:</p>
  
  <pre><code>var logger = LogManager.GetCurrentClassLogger();
  var orderId = 123;
  logger.Debug("What is going on here", orderId);
  </code></pre>
  
  <p>Is there a good way to do this and keep using NLog? Or do I have to roll my own logger and skip NLog when these are the requirements?</p>