New "log.txt" file on each App launch and archive old "log.txt" with "date time" filename: possible?

649 views
Skip to first unread message

cryodream

unread,
Nov 5, 2013, 6:58:28 PM11/5/13
to nlog-...@googlegroups.com
As the title says: I would like to have Nlog to create a new file named "log.txt" on each application start. At the same time, I would like to have the old log archived with the filename as file created "date_time.txt".

Reasons:
1) I pretty much hate loooong logs, especialy for a small tasks applications, where you need to scroll thousand of lines to find the few lines from the last run.
2) I like having the log file with the static name. I can open LogExpert or some other log viewer and either have the log opened from previous session or at least quickly use "recent files". Having the log file created as datetime.txt - a pain to use.
3) Having the log on every application start, I need to have archiving of older logs, to be able to have a look at logs from days/weeks before.

The problem is - I can't find a way to achieve that with only using NLog configuration. From what I gathered, I either use log filename as datetime straight away, this way I achieve a new file on app start - which is not good (point 2). Or I use same name log eg: "log.txt" and use size limit, which still is not so usefull, as having the log represent only current/last run of the app.

Could I be missing something and there actually is a way to achieve this with only NLog configuration?
If not, what would be the easiest way to achieve this?

Kim Christensen

unread,
Nov 6, 2013, 2:47:49 PM11/6/13
to nlog-...@googlegroups.com
You should be able to use something like this:

<target name="file" xsi:type="File" fileName="log${cached:${longdate}:cached=true}.LOG" />

to create and use a new log file based on the date on every application start.
Reply all
Reply to author
Forward
0 new messages