title: How can I configure NLog in .NET Core with appsettings.json instead of an nlog.config file?
body: <p>The NLog documentation explains how to configure NLog for .NET Core applications by using an <code>nlog.config</code> XML file. However, I'd prefer to have just one configuration file for my application - <code>appsettings.json</code>. For .NET Framework apps, it's possible to put the NLog configuration in <code>app.config</code> or <code>web.config</code>. Is it possible to put the NLog config in <code>appsettings.json</code> in the same way?</p>
  
  <p>For example, how could I put this configuration example from the <a href="https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2" rel="noreferrer">NLog documentation for ASP.NET Core 2</a> into <code>appsettings.json</code>?</p>
  
  <pre class="lang-xml prettyprint-override"><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"
        autoReload="true"
        internalLogLevel="Info"
        internalLogFile="c:\temp\internal-nlog.txt"&gt;
  
    &lt;!-- enable asp.net core layout renderers --&gt;
    &lt;extensions&gt;
      &lt;add assembly="NLog.Web.AspNetCore"/&gt;
    &lt;/extensions&gt;
  
    &lt;!-- the targets to write to --&gt;
    &lt;targets&gt;
      &lt;!-- write logs to file  --&gt;
      &lt;target xsi:type="File" name="allfile" fileName="c:\temp\nlog-all-${shortdate}.log"
              layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" /&gt;
  
      &lt;!-- another file log, only own logs. Uses some ASP.NET core renderers --&gt;
      &lt;target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-own-${shortdate}.log"
              layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" /&gt;
    &lt;/targets&gt;
  
    &lt;!-- rules to map from logger name to target --&gt;
    &lt;rules&gt;
      &lt;!--All logs, including from Microsoft--&gt;
      &lt;logger name="*" minlevel="Trace" writeTo="allfile" /&gt;
  
      &lt;!--Skip non-critical Microsoft logs and so log only own logs--&gt;
      &lt;logger name="Microsoft.*" maxlevel="Info" final="true" /&gt; &lt;!-- BlackHole without writeTo --&gt;
      &lt;logger name="*" minlevel="Trace" writeTo="ownFile-web" /&gt;
    &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>