有没有办法在NLOG中仅设置一次可变值

发布于 2025-01-30 16:55:04 字数 581 浏览 1 评论 0原文

我试图以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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文