1

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);
Otiel
  • 18,404
  • 16
  • 78
  • 126
trouta
  • 426
  • 3
  • 12

1 Answers1

1

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

Xharze
  • 2,703
  • 2
  • 17
  • 30
  • Thanks for the info, but it doesn't seem to work, I added the following to the config archiveFileName="c:\SupportLogs\${event-context:item=MessageId}.txt" archiveEvery="Minute" – trouta May 28 '13 at 16:27
  • Yeah, sorry event-context aren't available at during archiving, well it will always be empty. I'm changing my answer – Xharze May 28 '13 at 22:23