NLog save entries to database(postgresql), - nlog

Search on many post, all compared to almost identical but somehow its doesn't send entries to DB.
logging file works, but database not..
nlog.config
<?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"
internalLogLevel="Trace"
internalLogFile="c:logs\internallog.txt">
<extensions>
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<targets>
<target name="database" xsi:type="Database"
dbProvider="Npgsql.NpgsqlConnection, Npgsql"
connectionString="User ID=postgres;Password=123456;Host=localhost;Port=5432;Database=Telepati_Dev;">
<!--//Pooling=true;-->
<commandText>
insert into systemlogs(log_date,log_level,log_logger,log_message,log_machine_name, log_user_name, log_call_site, log_thread, log_exception, log_stacktrace) values(#time_stamp, #level, #logger, #message,#machinename, #user_name, #call_site, #threadid, #log_exception, #stacktrace);
</commandText>
<parameter name="#time_stamp" layout="${longdate}" />
<parameter name="#level" layout="${level}" />
<parameter name="#logger" layout="${logger}" />
<parameter name="#message" layout="${message}" />
<parameter name="#machinename" layout="${machinename}" />
<parameter name="#user_name" layout="${windows-identity:domain=true}" />
<parameter name="#call_site" layout="${callsite:filename=true}" />
<parameter name="#threadid" layout="${threadid}" />
<parameter name="#log_exception" layout="${exception}" />
<parameter name="#stacktrace" layout="${stacktrace}" />
</target>
<target xsi:type="File" name="ownFile-web" fileName="c:\logs\ApplicationLogs-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} CorrelationId=${aspnet-item:variable=CorrelationId} ${exception:format=tostring}|url: ${aspnet-request-url}|controller: ${aspnet-MVC-Controller}, action: ${aspnet-mvc-action}" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- BlackHole without writeTo -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
Api project gets dbcontext from data layer so does Npgsql reference
here is API nugget refs;
and data layer packages;
here are some contents of "internallog.txt";
2020-05-31 02:07:32.3212 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.3503 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.3642 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.3774 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.3934 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.4091 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.4245 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.4403 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.4551 Trace Opening c:\logs\ApplicationLogs-2020-05-31.log with allowFileSharedWriting=False
2020-05-31 02:07:32.4771 Debug Targets for Microsoft.EntityFrameworkCore.Database.Command by level:
2020-05-31 02:07:32.4771 Debug Trace =>
2020-05-31 02:07:32.4771 Debug Debug =>
2020-05-31 02:07:32.4947 Debug Info =>
2020-05-31 02:07:32.4947 Debug Warn => ownFile-web
2020-05-31 02:07:32.4947 Debug Error => ownFile-web
2020-05-31 02:07:32.5119 Debug Fatal => ownFile-web
2020-05-31 02:07:32.5119 Debug Targets for Microsoft.EntityFrameworkCore.Query by level:
2020-05-31 02:07:32.5119 Debug Trace =>
2020-05-31 02:07:32.5279 Debug Debug =>
2020-05-31 02:07:32.5279 Debug Info =>
2020-05-31 02:07:32.5279 Debug Warn => ownFile-web
2020-05-31 02:07:32.5428 Debug Error => ownFile-web
2020-05-31 02:07:32.5428 Debug Fatal => ownFile-web
2020-05-31 02:07:32.5428 Debug Targets for Microsoft.EntityFrameworkCore.Database.Transaction by level:
2020-05-31 02:07:32.5594 Debug Trace =>
2020-05-31 02:07:32.5594 Debug Debug =>
2020-05-31 02:07:32.5704 Debug Info =>
2020-05-31 02:07:32.5704 Debug Warn => ownFile-web
2020-05-31 02:07:32.5704 Debug Error => ownFile-web
2020-05-31 02:07:32.5856 Debug Fatal => ownFile-web
2020-05-31 02:07:32.5856 Debug Targets for Microsoft.EntityFrameworkCore.Database.Connection by level:
2020-05-31 02:07:32.5856 Debug Trace =>
2020-05-31 02:07:32.6033 Debug Debug =>
2020-05-31 02:07:32.6033 Debug Info =>
2020-05-31 02:07:32.6033 Debug Warn => ownFile-web
2020-05-31 02:07:32.6186 Debug Error => ownFile-web
2020-05-31 02:07:32.6186 Debug Fatal => ownFile-web
2020-05-31 02:07:32.6403 Debug Targets for Microsoft.EntityFrameworkCore.Update by level:
whats missing here?

There isn't a rule that writes to the database target in your config.
E.g. Replace
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
With
<logger name="*" minlevel="Trace" writeTo="ownFile-web, database" />

Related

Nlog Delete SQLite longer than X days

xsi:type="File" has maxArchiveFiles="5" archiveEvery="Day" properties. Is that possibble to delete db content older than X days?
xsi:type="Database" has rules for that purpose?
My sample Nlog.config;
<?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"
autoReload="true"
throwExceptions="false"
throwConfigExceptions="true"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<targets>
<!--target name="logfile" xsi:type="File" fileName="file.txt" /!-->
<target xsi:type="Database"
name="db"
dbProvider="System.Data.SQLite.SQLiteConnection, System.Data.SQLite"
connectionString="Data Source=log.db3;"
commandType="Text"
commandText="INSERT into Log(Timestamp, Loglevel, Callsite, Message) values(#Timestamp, #Loglevel, #Callsite, #Message)"
>
<parameter name="#Timestamp" layout="${longdate}"/>
<parameter name="#Loglevel" layout="${level:uppercase=true}"/>
<parameter name="#Callsite" layout="${callsite:filename=true}"/>
<parameter name="#Message" layout="${message}"/>
</target>
<target name="colouredConsole" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false" layout="${longdate}|${pad:padding=5:inner=${level:uppercase=true}}|${message}">
<highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGray" />
<highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
<highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="colouredConsole" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="colouredConsole" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="colouredConsole" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="db" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="db" />
</rules>
</nlog>
How to delete sqlite db content older than 7 days?
Some people suggests EnsureDb(); it works but I want to ask any possibility to set from xsi:type="Database" parameters?
private static void EnsureDb()
{
if (File.Exists("log.db3"))
{
using (SQLiteConnection connection = new SQLiteConnection("Data Source=log.db3"))
using (SQLiteCommand command = new SQLiteCommand(
"DELETE FROM Log WHERE Timestamp <= datetime('now', '-7 day');",
connection))
{
connection.Open();
command.ExecuteNonQuery();
}
return;
}
using (SQLiteConnection connection = new SQLiteConnection("Data Source=log.db3"))
using (SQLiteCommand command = new SQLiteCommand(
"CREATE TABLE Log (Timestamp TEXT, Loglevel TEXT, Callsite TEXT, Message TEXT)",
connection))
{
connection.Open();
command.ExecuteNonQuery();
}
}

NLog throws an error when loading an XmlLayout configuration file

I am attempting to configure NLog to output error logs in an XML format, however, NLog is not properly loading the configuration.
Here is the LAYOUT portion of my configuration:
<layout xsi:type="XmlLayout" includeAllProperties="true" propertiesElementKeyAttribute="" propertiesElementName="{0}" elementName="errorlog">
<attribute name="time" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}" />
<element name="processname" value="${processname}" />
<element name="logger" value="${logger}" />
<element name="message" value="${message}" />
</layout>
When calling the LogManager.GetCurrentClassLogger() method, the following error is generated:
Parameter name not supported on XmlLayout
Here are the additional details captured in the NLog error log file:
2019-03-04 16:25:39.9645 Trace Scanning Property Renderers 'System.Collections.ObjectModel.ReadOnlyCollection`1[NLog.LayoutRenderers.LayoutRenderer]' System.Collections.ObjectModel
2019-03-04 16:25:39.9645 Trace Scanning LevelLayoutRenderer 'Layout Renderer: ${level}'
2019-03-04 16:25:39.9645 Debug Setting 'XmlLayout.name' to 'processname'
2019-03-04 16:25:39.9835 Warn Error when setting 'processname' on attibute 'name' Exception: System.NotSupportedException: Parameter name not supported on XmlLayout
at NLog.Internal.PropertyHelper.SetPropertyFromString(Object obj, String propertyName, String value, ConfigurationItemFactory configurationItemFactory)
at NLog.Config.LoggingConfigurationParser.ConfigureObjectFromAttributes(Object targetObject, ILoggingConfigurationElement element, Boolean ignoreType)
2019-03-04 16:25:39.9835 Error Parsing configuration from C:\Users\<user>\Documents\Visual Studio 2017\Projects\TestingNlog\TestingNlog\bin\Debug\NLog.config failed. Exception: NLog.NLogConfigurationException: Exception when parsing C:\Users\<user>\Documents\Visual Studio 2017\Projects\TestingNlog\TestingNlog\bin\Debug\NLog.config. ---> System.NotSupportedException: Parameter name not supported on XmlLayout
If I remove the ELEMENT tags from the configuration file, I am able to generate a partial log file with just the single XML element ERRORLOG with the 2 specified attributes. However, I have not found a way to include the ELEMENT tags in my output log files.
NLog.dll - v4.6.0.9068
C# .NET - v4.7.2
Any ideas or assistance would be greatly appreciated!
-Kasey911
Snakefoot is correct,
this has been changed after NLog 4.6 RC 1
In NLog 4.6 RC 1
<layout xsi:type="XmlLayout" elementName='logevent'>
<attribute name="time" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<element elementName="message" elementValue="${message}" />
</layout>
In NLog 4.6 RC 2 (not released yet), and probably RTM
<layout xsi:type="XmlLayout" elementName='logevent'>
<attribute name="time" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<element name="message" value="${message}" />
</layout>

Jetty IncludeCipherSuites

i face the issue, that my jetty (9.4.7) doesn't want to start due a configuration error after including CipherSuites in jetty-ssl.xml.
I just receive following configuration error:
2018-09-13 16:10:02.896:WARN:oejx.XmlConfiguration:main: Config error at <Set name="IncludeCipherSuites">|/jetty-ssl.xml
2018-09-13 16:10:02.897:WARN:oejx.XmlConfiguration:main: Config error at <New class="org.eclipse.jetty.server.SslConnectionFactory"><Set name="IncludeCipherSuites">| <Array l
2018-09-13 16:10:02.897:WARN:oejx.XmlConfiguration:main:
java.security.PrivilegedActionException: org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$1: class org.eclipse.jetty.server.SslConnectionFactory.setIncludeCipherSuites(class [Ljava.lang.String;)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1507)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:221)
at org.eclipse.jetty.start.Main.start(Main.java:506)
at org.eclipse.jetty.start.Main.main(Main.java:78)
Caused by:
org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$1: class org.eclipse.jetty.server.SslConnectionFactory.setIncludeCipherSuites(class [Ljava.lang.String;)
I've used the following xml to include Cipher Suites:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "configure_9_3.dtd">
<!-- ============================================================= -->
<!-- Base SSL configuration -->
<!-- This configuration needs to be used together with 1 or more -->
<!-- of jetty-https.xml or jetty-http2.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add a SSL Connector with no protocol factories -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="acceptors" type="int"><Property name="jetty.ssl.acceptors" deprecated="ssl.acceptors" default="-1"/></Arg>
<Arg name="selectors" type="int"><Property name="jetty.ssl.selectors" deprecated="ssl.selectors" default="-1"/></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<!-- uncomment to support proxy protocol
<Item>
<New class="org.eclipse.jetty.server.ProxyConnectionFactory"/>
</Item>-->
</Array>
</Arg>
<Set name="host"><Property name="jetty.ssl.host" deprecated="jetty.host" /></Set>
<Set name="port"><Property name="jetty.ssl.port" deprecated="ssl.port" default="20743" /></Set>
<Set name="idleTimeout"><Property name="jetty.ssl.idleTimeout" deprecated="ssl.timeout" default="30000"/></Set>
<Set name="soLingerTime"><Property name="jetty.ssl.soLingerTime" deprecated="ssl.soLingerTime" default="-1"/></Set>
<Set name="acceptorPriorityDelta"><Property name="jetty.ssl.acceptorPriorityDelta" deprecated="ssl.acceptorPriorityDelta" default="0"/></Set>
<Set name="acceptQueueSize"><Property name="jetty.ssl.acceptQueueSize" deprecated="ssl.acceptQueueSize" default="0"/></Set>
<Get name="SelectorManager">
<Set name="connectTimeout"><Property name="jetty.ssl.connectTimeout" default="15000"/></Set>
<Set name="reservedThreads"><Property name="jetty.ssl.reservedThreads" default="-2"/></Set>
</Get>
<New class="org.eclipse.jetty.server.SslConnectionFactory">
<Set name="IncludeCipherSuites">
<Array type="java.lang.String">
<Item>ECDHE-ECDSA-CHACHA20-POLY1305</Item>
<Item>ECDHE-RSA-CHACHA20-POLY1305</Item>
<Item>ECDHE-ECDSA-AES128-GCM-SHA256</Item>
<Item>ECDHE-RSA-AES128-GCM-SHA256</Item>
<Item>ECDHE-ECDSA-AES256-GCM-SHA384</Item>
<Item>ECDHE-RSA-AES256-GCM-SHA384</Item>
<Item>DHE-RSA-AES128-GCM-SHA256</Item>
<Item>DHE-RSA-AES256-GCM-SHA384</Item>
<Item>ECDHE-ECDSA-AES128-SHA256</Item>
<Item>ECDHE-RSA-AES128-SHA256</Item>
<Item>ECDHE-ECDSA-AES128-SHA</Item>
<Item>ECDHE-RSA-AES256-SHA384</Item>
<Item>ECDHE-RSA-AES128-SHA</Item>
<Item>ECDHE-ECDSA-AES256-SHA384</Item>
<Item>ECDHE-ECDSA-AES256-SHA</Item>
<Item>ECDHE-RSA-AES256-SHA</Item>
<Item>DHE-RSA-AES128-SHA256</Item>
<Item>DHE-RSA-AES128-SHA</Item>
<Item>DHE-RSA-AES256-SHA256</Item>
<Item>DHE-RSA-AES256-SHA</Item>
<Item>ECDHE-ECDSA-DES-CBC3-SHA</Item>
<Item>ECDHE-RSA-DES-CBC3-SHA</Item>
<Item>EDH-RSA-DES-CBC3-SHA</Item>
<Item>AES128-GCM-SHA256</Item>
<Item>AES256-GCM-SHA384</Item>
<Item>AES128-SHA256</Item>
<Item>AES256-SHA256</Item>
<Item>AES128-SHA</Item>
<Item>AES256-SHA</Item>
<Item>DES-CBC3-SHA</Item>
</Array>
</Set>
</New>
</New>
</Arg>
</Call>
<!-- =========================================================== -->
<!-- Create a TLS specific HttpConfiguration based on the -->
<!-- common HttpConfiguration defined in jetty.xml -->
<!-- Add a SecureRequestCustomizer to extract certificate and -->
<!-- session information -->
<!-- =========================================================== -->
<New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Arg><Ref refid="httpConfig"/></Arg>
<Call name="addCustomizer">
<Arg>
<New class="org.eclipse.jetty.server.SecureRequestCustomizer">
<Arg name="sniHostCheck" type="boolean"><Property name="jetty.ssl.sniHostCheck" default="true"/></Arg>
<Arg name="stsMaxAgeSeconds" type="int"><Property name="jetty.ssl.stsMaxAgeSeconds" default="-1"/></Arg>
<Arg name="stsIncludeSubdomains" type="boolean"><Property name="jetty.ssl.stsIncludeSubdomains" default="false"/></Arg>
</New>
</Arg>
</Call>
</New>
</Configure>
I've also tried different ways of setting this CipherSuites, but always it ends in the same behavior.
Thanks for your help in advance.
Wrong class was used.
Had to use <New class="org.eclipse.jetty.util.ssl.SslContextFactory">
Problem is solved.
Thanks!

NLog json fields missing when using a network target

I'm using NLog to log in json format, using the targets below (file and network).
When logging to the file target or both file and network, the messages are logged fine.
However, when using only the network target, dbResponseTime and messagesSentTotal will not be included in the message (in fact, any attribute using a layout with "event-properties:item="). All the other properties are present, including the one defined in the end (module).
<?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"
autoReload="true"
throwExceptions="false" internalLogLevel="Off">
<targets>
<target name="logHealthCheck" xsi:type="File"
fileName="D:\Logs\HealthCheck.${shortdate}.json"
archiveFileName="D:\Logs\HealthCheck.{#}.json"
archiveNumbering="DateAndSequence"
archiveAboveSize="33554432"
archiveDateFormat="yyyy-MM-dd">
<layout xsi:type="JsonLayout">
<attribute name="timestamp" layout="${date:universalTime=true:format=o}" />
<attribute name="machineName" layout="${machinename}" />
<attribute name="environment" layout="${literal:text=DEV}" />
<attribute name="dbResponseTime" layout="${event-properties:item=dbResponseTime}" encode="false"/>
<attribute name="messagesSentTotal" layout="${event-properties:item=messagesSentTotal}" encode="false"/>
<attribute name="module" layout="${literal:text=core}" />
</layout>
</target>
<target name="logHealthCheckNetwork" xsi:type="Network" address="tcp://127.0.0.1:1514" newLine="true">
<layout xsi:type="JsonLayout">
<attribute name="timestamp" layout="${date:universalTime=true:format=o}" />
<attribute name="machineName" layout="${machinename}" />
<attribute name="environment" layout="${literal:text=DEV}" />
<attribute name="dbResponseTime" layout="${event-properties:item=dbResponseTime}" encode="false"/>
<attribute name="messagesSentTotal" layout="${event-properties:item=messagesSentTotal}" encode="false"/>
<attribute name="module" layout="${literal:text=core}" />
</layout>
</target>
<rules>
<logger name="HealthCheck" minlevel="Debug" writeTo="logHealthCheck,logHealthCheckNetwork">
<filters>
</filters>
</logger>
</rules>
</nlog>
Switched on the internal log, and no error is recorded. Trace below:
2018-02-02 16:43:07.7837 Trace Scanning LoggingRule 'logNamePattern: (HealthCheck:Equals) levels: [ Debug Info Warn Error Fatal ] appendTo: [ logHealthCheckNetwork ]'
2018-02-02 16:43:07.7993 Trace Scanning NetworkTarget 'Network Target[logHealthCheckNetwork]'
2018-02-02 16:43:07.8305 Trace Scanning SimpleLayout ''tcp://127.0.0.1:1514''
2018-02-02 16:43:07.8305 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2018-02-02 16:43:07.9085 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:07.9085 Trace Scanning SimpleLayout ''${date:universalTime=true:format=o}''
2018-02-02 16:43:07.9241 Trace Scanning DateLayoutRenderer 'Layout Renderer: ${date}'
2018-02-02 16:43:07.9397 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:07.9397 Trace Scanning SimpleLayout ''${machinename}''
2018-02-02 16:43:07.9553 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2018-02-02 16:43:07.9553 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:07.9709 Trace Scanning SimpleLayout ''${literal:text=DEV}''
2018-02-02 16:43:07.9709 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2018-02-02 16:43:08.0177 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:08.0333 Trace Scanning SimpleLayout ''${event-properties:item=dbResponseTime}''
2018-02-02 16:43:08.0333 Trace Scanning EventPropertiesLayoutRenderer 'Layout Renderer: ${event-properties}'
2018-02-02 16:43:08.0801 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:08.0801 Trace Scanning SimpleLayout ''${event-properties:item=messagesSentTotal}''
2018-02-02 16:43:08.3453 Trace Scanning JsonAttribute 'NLog.Layouts.JsonAttribute'
2018-02-02 16:43:08.3609 Trace Scanning SimpleLayout ''${literal:text=core}''
2018-02-02 16:43:08.3765 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
NLog 4.5.4 has been released that fixes the issue: https://github.com/NLog/NLog/issues/2573

dotnet core nlog running on Linux logs only one entry

I am running an aspnet core site on Linux using Kestrel. I have set up nlog to log to csv files. All is well in my Windows development environment, but when I run it on Linux I only get one entry in the log file. I turned on nlog tracing and found the following error in the output:
2016-09-09 07:22:46.2123 Error Error has been raised. Exception: System.IO.IOException: The file '/var/aspnetcore/CSWebSite/releases/20160909061254/logs/archives/own-log.20160908.csv' already exists.
at System.IO.UnixFileSystem.MoveFile(String sourceFullPath, String destFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)
2016-09-09 07:22:46.2123 Error Error has been raised. Exception: System.IO.IOException: The file '/var/aspnetcore/CSWebSite/releases/20160909061254/logs/archives/all-log.20160907.csv' already exists.
at System.IO.UnixFileSystem.MoveFile(String sourceFullPath, String destFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)
This is my nlog.config:
<?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">
<extensions>
<!--enable NLog.Web for ASP.NET Core-->
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<targets>
<!-- https://github.com/nlog/nlog/wiki/File-target -->
<!-- http://stackoverflow.com/questions/34679727/use-nlog-in-asp-net-5-application -->
<target name="allfile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target name="allfile" xsi:type="File"
fileName="${basedir}/logs/all-logfile.csv"
archiveFileName="${basedir}/logs/archives/all-log.{#}.csv"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="28"
concurrentWrites="true"
keepFileOpen="false"
encoding="utf-8">
<layout xsi:type="CSVLayout">
<column name="time" layout="${longdate}" />
<column name="logger" layout="${logger}" />
<column name="authtype" layout="${aspnet-user-authtype}" />
<column name="identity" layout="${aspnet-user-identity}" />
<column name="level" layout="${uppercase:${level}}" />
<column name="message" layout="${message} ${exception:format=ToString,StackTrace}" />
</layout>
</target>
</target>
<target name="ownfile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target name="ownfile" xsi:type="File"
fileName="${basedir}/logs/own-logfile.csv"
archiveFileName="${basedir}/logs/archives/own-log.{#}.csv"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="28"
concurrentWrites="true"
keepFileOpen="false"
encoding="utf-8">
<layout xsi:type="CSVLayout">
<column name="time" layout="${longdate}" />
<column name="logger" layout="${logger}" />
<column name="authtype" layout="${aspnet-user-authtype}" />
<column name="identity" layout="${aspnet-user-identity}" />
<column name="level" layout="${uppercase:${level}}" />
<column name="message" layout="${message} ${exception:format=ToString,StackTrace}" />
</layout>
</target>
</target>
<target xsi:type="Null" name="blackhole" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Debug" writeTo="allfile" />
<!--Skip Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Debug" writeTo="ownFile" />
</rules>
</nlog>
I have concurrent writes true and keepFileOpen false which seems necessary as kestrel forks multiple dotnet processes on Linux.
Is this a bug or is my configuration incorrect?

Resources