title: NLog how to access RequestId?
body: <p>I want to save <code>Activity.Current?.Id ?? HttpContext.TraceIdentifier</code> into database, because that is Request Id which user see in default error view. But how ? <strong>HttpContext</strong> is not available in startup.cs and i tried access HttpContext in <strong>LayoutRenderer</strong> not successfully.</p>
  
  <p><strong>Error method in HomeController</strong></p>
  
  <pre><code>public IActionResult Error()
  {
      var model = new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier };
  
      return View(model);
  }
  </code></pre>
  
  <p>I tried LayoutRenderer</p>
  
  <pre><code>namespace Copacking.Web.Utils
  {
      [LayoutRenderer("requestid")]
      public class NLogRequestIdLayoutRenderer : LayoutRenderer
      {
          protected override void Append(StringBuilder builder, LogEventInfo logEvent)
          {
              builder.Append(Activity.Current?.Id ?? HttpContext.TraceIdentifier);
          }
      }
  }
  </code></pre>
  
  <p>but I am getting an error with <strong>HttpContext</strong>, because object reference is required.</p>
  
  <p>How can i solve it ? In <strong>Nlog.config</strong> file <strong>${aspnet-traceidentifier}</strong> is working but <strong>${activityid}</strong> variable is empty :/</p>