The example NLog.config-xml-file tries to show many things at once. How to redirect output to multiple files, and capture different HttpContext-details. More a demonstration of what is possible, and inspiration for the user to think up their own perfect logging-configuration.
But instead of being a prototype/showcase/exercise of what is possible, then it might be better to provide NLog.config that works out of the box for 80 pct of users. Maybe something basic like this:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
throwConfigExceptions="true">
<extensions>
<add assembly="NLog.Extensions.Logging" />
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<targets async="true">
<target name="logDebugger" xsi:type="Debugger" />
<target name="logConsole" xsi:type="Console" layout="${MicrosoftConsoleLayout}" />
<target name="logFile" xsi:type="File" fileName="log-${shortdate}.txt" maxArchiveFiles="30">
<layout xsi:type="MicrosoftConsoleJsonLayout" includeScopes="true" includeActivityIds="true">
<state name="url" layout="${aspnet-request-url}" />
<state name="method" layout="${aspnet-request-method}" />
<state name="statuscode" layout="${aspnet-response-statuscode}" />
<state name="requestip" layout=" ${aspnet-request-ip} " />
<state name="hostname" layout="${hostname}" />
<state name="servicename" layout="${host-appname}" />
<state name="environment" layout="${host-environment}" />
</layout>
</target>
</targets>
<rules>
<logger name="System.*" finalMinLevel="Warn" />
<logger name="Microsoft.*" finalMinLevel="Warn" />
<logger name="Microsoft.Hosting.Lifetime*" finalMinLevel="Info" /> <!-- Overrides previous rule -->
<logger name="*" minLevel="Info" writeTo="logDebugger" />
<logger name="*" minLevel="Info" writeTo="logConsole" />
<logger name="*" minLevel="Info" writeTo="logFile" />
</rules>
</nlog>
See also: https://github.com/NLog/NLog/wiki/Tutorial
Maybe update example-project to also setup NLog-MiddleWare for logging http-request that are failing/slow?
The example
NLog.config-xml-file tries to show many things at once. How to redirect output to multiple files, and capture different HttpContext-details. More a demonstration of what is possible, and inspiration for the user to think up their own perfect logging-configuration.But instead of being a prototype/showcase/exercise of what is possible, then it might be better to provide
NLog.configthat works out of the box for 80 pct of users. Maybe something basic like this:See also: https://github.com/NLog/NLog/wiki/Tutorial
Maybe update example-project to also setup NLog-MiddleWare for logging http-request that are failing/slow?