0

I log some stuff with LogEventInfo, because I'm adding a variable property called Action to each log. In my target the layout is simple, layout="${message}", but fileName is complex, fileName="C:\log\${date:format=yyyy-MM-dd HH-mm-ss} ${event-properties:item=Action}.log".

But I still want to restrict the space taken with all these log files. It doesn't matter if it's by size, or date, or number of files. How do I archive log files with such custom file name?

There is an answer from 2013 stating that this is not possible, but I'm hoping that that answer is now incorrect, even if it was correct back then.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • Have you checked the [documentation](https://github.com/NLog/NLog/wiki/FileTarget-Archive-Examples) and this [thread](https://stackoverflow.com/questions/50501773/how-to-set-nlog-max-file-size/50501933)? – Pavel Anikhouski Jan 30 '20 at 18:44
  • @Pavel I did try `archiveAboveSize="1"`. The file is not archived if a log *would* exceed the size, but rather if the size is already exceeded on the *next* log. This messes up the file names. But maybe I'm doing it wrong, and if you have a solution please post it. – Dialecticus Jan 30 '20 at 19:03
  • _Size in bytes above which log files will be automatically archived_ I don't think that log file with 1 byte size make sense. Try to follow an official sample, set the size to 10240 (10 kB). Refer to options [description](https://github.com/NLog/NLog/wiki/File-target#archival-options) – Pavel Anikhouski Jan 30 '20 at 19:16
  • @Pavel, this will set the size of one file. How does this help me? I don't need to set the size of one file. In fact one file in my case has only one message, because file name has current date and time up to a minute, so size of one file does not matter. – Dialecticus Jan 30 '20 at 20:42

1 Answers1

0

In the end my solution was to delete all *.log files from the folder, except the N newest ones, before I write a new log. These logs are not of the regular kind, so special cleanup for special logging case is fine.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103