O
O
Oblomov952016-10-21 14:13:20
C++ / C#
Oblomov95, 2016-10-21 14:13:20

How to delete old logs (NLog)?

Unable to delete old logs, does anyone know what could be the problem?

<target
    name="infoLog"
    xsi:type="File"
    fileName="${logDir}/info.{#}.txt"
    layout="${info}"
    archiveFileName="${logDir}/Log.info.{#}.txt"
    archiveEvery="day"
    archiveNumbering="Rolling"
    maxArchiveFiles="2"
    concurrentWrites="true" />

 <target
  name="errorLog"
  xsi:type="File"
  fileName="${logDir}/error.{#}.txt"
  layout="${error}"
  archiveFileName="${logDir}/Log.error.{#}.txt"
  archiveEvery="Day"
  archiveNumbering="Rolling"
  maxArchiveFiles="2"
  concurrentWrites="true" />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Patutin, 2016-10-27
@Oblomov95

You've done almost everything right. But,
1. For infoLog, archiveEvery="day" was specified, but you need to capitalize it.
2. maxArchiveFiles is responsible for the number of archives (these are files that are created after the current log is filled).
Here is an example target:

<target
     name="infoLog"
     xsi:type="File"
     fileName="${logDir}/Log.info.txt"     
     archiveFileName="${logDir}/Log.info.{#}.txt"
     archiveEvery="Minute"
     archiveNumbering="Rolling"
     maxArchiveFiles="2"
     concurrentWrites="true" />

And the code that writes to the log every 20 seconds:
for (int i = 0; i < 100; i++)
            {
                logger.Info("{0} Log Test", i);
                Thread.Sleep(TimeSpan.FromSeconds(20));
            }

There will always be 3 files in the log folder:
Log.info.txt
Log.info.0.txt
Log.info.1.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question