NLog - Cleaning up log files that have dynamic file names

北慕城南 提交于 2021-02-08 09:35:08

问题


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.

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);

回答1:


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



来源:https://stackoverflow.com/questions/16741044/nlog-cleaning-up-log-files-that-have-dynamic-file-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!