Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this NLog configuration not archive?

What is wrong with this NLog configuration? Why aren't the archive logs created in "c:\TempFiles\AppLogs"? Oddly, it seems to work for archiveEvery="Minute". What's going on?

<?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="Debug" internalLogFile="../logs/nlog.log" throwExceptions="true">

  <!-- make sure to set 'Copy To Output Directory' option for this file -->
  <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->

  <extensions>
    <add assembly="NGinnBPM.MessageBus"/>
  </extensions>
  <variable name="logDir" value="${basedir}/logs"/>
  <variable name="LogsLocation" value="c:\TempFiles\AppLogs" />

  <targets>
    <target name="err" xsi:type="File"
            archiveFileName="${LogsLocation}\logs\contact_errors.{#}.txt"
            archiveEvery="Day"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          concurrentWrites="true"
            fileName="${logDir}/contact_errors.${shortdate}.log" layout="${time}|T${threadid}|M${mdc:nmbrecvmsg}|${level}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}" />
    <target name="nginn" xsi:type="File"
            archiveFileName="${LogsLocation}\logs\contact_nginn.{#}.txt"
            archiveEvery="Day"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          concurrentWrites="true"
            fileName="${logDir}/contact_nginn.${shortdate}.log" layout="${time}|T${threadid}|M${mdc:nmbrecvmsg}|${level}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}" />
    <target name="all" xsi:type="File"
            archiveFileName="${LogsLocation}\logs\contact.{#}.txt"
            archiveEvery="Day"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          concurrentWrites="true"
            fileName="${logDir}/contact.${shortdate}.log" layout="${time}|T${threadid}|M${mdc:nmbrecvmsg}|${level}|${logger}|${message}"/>

  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="all" />
    <logger name="Slate.*" minlevel="Trace" writeTo="all" final="true"/>
    <logger name="*" minlevel="Error" writeTo="err" />
    <logger name="NGinnBPM.*" minlevel="Trace" writeTo="nginn" final="true"/>

  </rules>
</nlog>
like image 412
Phil C Avatar asked Jan 20 '15 15:01

Phil C


People also ask

How does NLog archive work?

So the NLog archiving feature does not work the way you want it to. It just places the last file of the month to the archive folder not all. This way you will get one file per day and the file will be transferred to the archive folder each day. The archive will keep the file for one year.

What can be configured with this NLog config file?

The following types can be configured: Targets - the destinations of a logevent, e.g. file, database, console. Layout - the layout e.g. json, csv, plain-text (default) Layout renderers - the template markers, e.g. ${message}, ${exception}, ${date}

Where are NLog logs stored?

nlog file can be found at: C:\Program Files (x86)\Pleasant Solutions\Pleasant Password Server\www\web. nlog.


1 Answers

All the filenames of all targets contain the expression ${shortdate}, therefore a new logfile is created every day.

The archive period for all targets is set to Day which ought to archive the log file every day (archive and empty current log file).

Since a new logfile is created every day, the current logfile is never older than one day. Therefore, there is nothing to archive.

You could either change the filename of the log (omit the date since it isn't useful if you use archiving), or make sure that the archiving interval is shorter than the lifespan of the logfile (for testing, simply try to set it to Minute).

like image 166
marapet Avatar answered Nov 15 '22 03:11

marapet