14

I need NLog to overwrite the log file when the application is restarted. Currently it appends to existing file. For example I have something like this in my NLog.config

<targets>
  <target xsi:type="File" name="fileLog" 
          fileName="${longdate}.log" layout="${message}" />
</targets>

It would be nice if I was able to add to <target> something like this append="false" so instead of appending to existing log it would overwrite.

Vadim
  • 21,044
  • 18
  • 65
  • 101

1 Answers1

22

replace your config section

<targets>
  <target xsi:type="File" name="fileLog" 
          fileName="${longdate}.log" layout="${message}" deleteOldFileOnStartup="true"/>
</targets>
burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
  • 2
    deleteOldFileOnStartup works only when the "FileName" parameter denotes a single file. In my case it's fileNmae="${longdate}.log". In this case it wouldn't work. However, for my app. I can change the name for the log file and this solution will work for me. Plus 1 and I'll accept your answer. – Vadim Nov 28 '12 at 16:57
  • how often are the files deleted, based on what, a day old, a month, file size? – Smith Feb 19 '18 at 01:51