I have tried to create a variable at config file
<variable name="fileName" value="${longdate}" />
<target name="info" keepFileOpen="true" xsi:type="File" fileName="${basedir}/logs/info/log_${fileName}.log"
encoding="utf-8" layout="${longdate} ${callsite} [${level}]: ${message}" />
but it create a lot log file. how to write a config file for implementing that create a new log file named by longdate every app starting up?
Thanks a lot.
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!
I have implementing it by inherit FileTarget class.
[Target("MyFirst")]
public sealed class MyFirstTarget : FileTarget
{
public MyFirstTarget()
{
DateTime t1 = DateTime.Now;
string s1 = t1.ToString("yyyy-MM-dd hh:mm:ss fff");
FileName = "${basedir}/logs/info/" + s1 + ".txt";
}
}
config file insert it
<extensions>
<add assembly="Ext1"/>
</extensions>
<target name="first" type="MyFirst" encoding="utf-8" layout="${longdate} ${callsite} [${level}]: ${message}" />
i thank it can be implemeted by a esay way.
You could use cached:
${longdate:cached=true}
See https://github.com/NLog/NLog/wiki/Cached-Layout-Renderer
Related, the latest example in that page
It does work, thanks a lot
Most helpful comment
It does work, thanks a lot