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
The way I solve it is by hardening the filename from code.
Here's an example for your case:
Using the Cached Layout Renderer
For a solution that doesn't require code, use the Cached Layout Renderer:
Using a custom Layout Renderer
The solution from above does not actually use the process start time. Instead, it uses the time when the first log message was routed to this target (e.g. first log to file). This can be a problem if, for example, you want the log files to reside in a directory that is named after the process start time.
In that case, a custom Layout Renderer may be used. Add the following class to your project:
And use it as follows:
This solution is based on the Process Info Layout Renderer.