title: Retrieving HttpContext in a Custom NLog Target
body: <p>I may me missing something basic here - but is it possible to retrieve the <code>HttpContext.Current</code> in a custom NLog event?</p>
  
  <p>I am trying to give each request a unique Guid so that I can correlate logging messages to a single event (i.e, tie together each log event for a single request).  So, I want to store this Guid in <code>HttpContext.Current.Items</code>, then retrieve it in the NLog target and include it in the log message.</p>
  
  <p>Here is my example target where I'd like to access <code>HttpContext.Current</code>:</p>
  
  <pre><code>[Target("AzureTableTarget")]
  public class AzureTableTarget : TargetWithLayout
  {
  
      public AzureTableTarget()
      {
          _appSettings = IoCResolver.Get&lt;IAppSettings&gt;();
      }
  
      protected override void Write(LogEventInfo logEvent)
      {
          var correlationId = HttpContext.Current; //This is always null
  
          var batchOperation = new TableBatchOperation();
          CxLogEventBuilder.Build(_appSettings, logEvent).ForEach(batchOperation.Insert);
          _loggingTable.ExecuteBatchAsync(batchOperation);
      }
  }
  </code></pre>