问题
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