How to set NLog's fileName to the process start date?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set NLog's fileName to the process start date?

vernicht
I tried

<target name="txtFile"
        xsi:type="File"
        fileName="${date:format=yyyy-MM-dd HH-mm-ss}.txt"
        layout="${longdate} ${level} ${message}"/>

but it creates a new file each minute. I realize that there is ${processinfo:property=StartTime} but I couldn't format it. I tried:

${processinfo:property=StartTime:format=yyyy-MM-dd HH-mm-ss}

but it doesn't work
Reply | Threaded
Open this post in threaded view
|

Re: How to set NLog's fileName to the process start date?

Jason LaFlair
Administrator
Take a look at the cache attribute:

http://nlog-project.org/wiki/Cached_layout_renderer

looks like you can change your fileName="${date:format=yyyy-MM-dd HH-mm-ss}.txt"

to

fileName="${date:format=yyyy-MM-dd HH-mm-ss:cache=true}.txt"