Tali
Tali

Reputation: 1

Nlog Create unique log file for every application startup

I would like to create a single log file for entire application. The log file name convection should includes date and time like this: MyLog_31122022_0915.log

Right now each class creates a new instance meaning a new log file. If I change the log file name convention, removing date and time, I get a single file, the problem is the the same file is used for each new run of the application.

How can it be done?

Upvotes: 0

Views: 495

Answers (1)

Rolf Kristensen
Rolf Kristensen

Reputation: 19867

You can use ${processinfo} to log process-starttime:

fileName="MyLog_${processinfo:StartTime:format=ddMMyyyy_HHmm:cached=true}.log"

You can adjust the DateTime-format to include seconds / milliseconds to make it more unique. Or you can include ${processid}:

fileName="MyLog_${processinfo:StartTime:format=ddMMyyyy_HHmmss:cached=true}_${processid}.log"

Upvotes: 1

Related Questions