I’m trying to log only Errors into the Windows syslog (events viewer), I tried many solutions but none of them run as expected. I still see warning messages in the Windows syslog.
It’s an Asp.Net Core project (nuget 2.2.0) with NLog 5.2.8.
I don’t have any a content related to log configuration in my appsettings.json file and here is the content of my nglog.config file.
What am I missing?
<?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" autoReload="true">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.WindowsEventLog"/>
</extensions>
<targets>
<target xsi:type="File" name="allfile" fileName="Backoffice_template.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring} |action: ${aspnet-mvc-action} |user: ${aspnet-user-identity}" archiveEvery="Day" encoding="utf-8"
archiveNumbering = "Date"
archiveDateFormat = "yyyyMMdd_HHmmss" archiveOldFileOnStartup="false" maxArchiveDays="30" />
<target name="EventLog" xsi:type="EventLog">
<logLevel>Error</logLevel>
</target>
<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" maxLevel="Warning" writeTo="allfile" />
<logger name="Microsoft.*" maxLevel="Warning" final="true" />
<logger name="System.Net.Http.*" maxlevel="Info" />
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" />
<logger name="*" minlevel="Error" writeTo="EventLog" final="true" />
</rules>
</nlog>
Logger is created like this:
var logger = LogManager.Setup().GetCurrentClassLogger();