有没有办法在NLOG中仅设置一次可变值
我试图以ASP.NET核心项目的方式设置NLOG,以使其读取日期,然后根据该日期创建文件目标。这就是我所拥有的:
<variable name ="CurrentDate" value="${longdate}"/>
<targets>
<target name="MyApp" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${CurrentDate}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${message}"
deleteOldFileOnStartup="false"/>
</targets>
但是我观察到的是,每次应用程序日志发生时,NLOG都会根据发生的时间日志创建一个新文件,该文件在目标目录中产生了巨大的混乱。
我希望在应用程序启动时仅读取一次我只能读取一次的“ CurrentDate”变量,以便每次应用程序启动时都会有一个单独的日志。
有什么想法如何完成?
I am trying to set NLog in ASP.NET Core project in a way that it would read the date ONCE and then create a file target based on that date. This is what I have:
<variable name ="CurrentDate" value="${longdate}"/>
<targets>
<target name="MyApp" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${CurrentDate}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${message}"
deleteOldFileOnStartup="false"/>
</targets>
However what I've observed is that every time application log occurs, NLog will create a new file based on the time log happened which creates a massive clutter in the target directory.
I would like this "CurrentDate" variable that I am using to be read only once when application starts so that I would have a separate log for each time the application starts.
Any ideas how this could be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论