How can I configure NLog in such a way that it will log to a database table (in my case SQL Server) and purge rows after a certain time period?
I am using NLog with the database target. The file target has multiple options to rollover and eventually delete log files (e.g. by date/time, size, etc.). I would like to be able to use something similar in NLog.
The following NLog file target configuration allows me to set logs to be kept for a time and then expire completely.
<targets async="true">
<target xsi:type="File"
name="TraceFile"
layout="${longdate} - ${level:uppercase=true} - ${callsite:className=true:fileName=true:includeSourcePath=true
:methodName=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
fileName="${logFolder}\${appName}\Trace\Trace.log"
archiveFileName="${logFolder}\${appName}\Trace\Trace_${shortdate}.log"
archiveNumbering="Sequence"
archiveEvery="Day"
maxArchiveFiles="5"
/>
<target xsi:type="File"
name="DebugFile"
layout="${longdate} - ${level:uppercase=true} - ${callsite:className=true:fileName=true:includeSourcePath=true
:methodName=true}: ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
fileName="${logFolder}\${appName}\Debug\Debug.log"
archiveFileName="${logFolder}\${appName}\Debug\Debug_${shortdate}.log"
archiveNumbering="Sequence"
archiveEvery="Day"
maxArchiveFiles="10"
/>
</targets>