NLog - 清理具有动态文件名的日志文件 [英] NLog - Cleaning up log files that have dynamic file names

查看:125
本文介绍了NLog - 清理具有动态文件名的日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序将通过排队系统接收消息,我想将每条消息记录到自己的文件中,文件名是消息 ID.我想出了如何使用文件名中的事件上下文来完成此操作.

I have an application that will be receiving messages through a queuing system, I would like to log each message to its own file, with the file name being the message id. I figured out how to accomplish this using the event-context within the filename.

虽然 maxArchiveFiles 设置没有任何影响,可能是因为我没有归档任何文件.使用此配置有什么方法可以利用 NLog 按日期或计数限制文件数量?

Though the maxArchiveFiles setting does not have any affect, probably because I'm not archiving any files. Using this configuration is there any way I can leverage NLog to limit the number of files either by date or count?

 <target name="testfile" xsi:type="File"
            layout="${message}"
            fileName="c:\SupportLogs\${event-context:item=MessageId}.txt"
            maxArchiveFiles="50"
            keepFileOpen="false"
            encoding="iso-8859-2" />


    NLog.Logger oLogger = NLog.LogManager.GetLogger("Test");
    NLog.LogEventInfo oEvent = new NLog.LogEventInfo(NLog.LogLevel.Debug, "", "My Message");
    oEvent.Properties["MessageId"] = Guid.NewGuid().ToString();
    oLogger.Log(oEvent);

推荐答案

很遗憾,目前在 NLog 中无法实现.您必须自己清理日志文件.

Unfortunately this is not possible in the NLog at the moment. You have to clean up the log files yourself.

这篇关于NLog - 清理具有动态文件名的日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆