Problem when adding timestamp to filelog

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

Problem when adding timestamp to filelog

Tim K
I've made an abstraction of NLog for my application to a static logging class which has 3 static Loggers. Now when I add the ${date:format=yyyyMMdd_hhmmss} in my target filename it gives me a new logfile every second. How can I fix the date stamp to the starting time of the application?

Couldn't find anything in the documentation for that?
Reply | Threaded
Open this post in threaded view
|

Re: Problem when adding timestamp to filelog

Jarek Kowalski
Administrator
You can use ${cached}:

${cached:${date:format=yyyyMMdd_hhmmss}}

${cached} causes the layout to be computed only once and saved for the
duration of the app.

Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Problem when adding timestamp to filelog

Tim K
Thanks alot Jarek! Did not see the ${cached} before!