ram dvash
ram dvash

Reputation: 190

Is it possible to archive logs based on size and on time using NLog

I am using NLog.

I would like to have a size-based file archival and a time-based file archival.

Meaning, every time the log file exceeds 10 MB a new log file is created. Also, every day a new log file is created.

It is clear how to do each of the above separately (https://github.com/NLog/NLog/wiki/FileTarget-Archive-Examples) but not how to use them in tandem.

Upvotes: 0

Views: 256

Answers (1)

Rolf Kristensen
Rolf Kristensen

Reputation: 19912

Without any details of the expected fileName-Layout, then this will work just fine in NLog 4.5 (and newer):

<target type="file" name="logfile" fileName="App-${shortdate}.log" archiveAboveSize="1000000" maxArchiveFiles="30" />

It will produce the following filenames (newest first)

  • App-20200216.log
  • App-20200216.2.log
  • App-20200216.1.log
  • App-20200215.log
  • App-20200214.log
  • App-20200214.1.log

See also: https://github.com/NLog/NLog/wiki/File-target#archive-old-log-files

Upvotes: 1

Related Questions