Skip to content

Commit

Permalink
Merge pull request #774 from remye06/fix-archiveoldfileonstartup-alt
Browse files Browse the repository at this point in the history
FIxed ArchiveOldFileOnStartup with layout renderer used in ArchiveFileName
  • Loading branch information
304NotModified committed Jul 17, 2015
2 parents ef8f106 + ef5a316 commit ca37ae5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/NLog/Targets/FileTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ protected override void Write(LogEventInfo logEvent)
this.DoAutoArchive(fileName, logEvent);
}

this.WriteToFile(fileName, bytes, false);
this.WriteToFile(fileName, logEvent, bytes, false);
}

/// <summary>
Expand Down Expand Up @@ -779,7 +779,7 @@ private void FlushCurrentFileWrites(string currentFileName, LogEventInfo firstLo
this.DoAutoArchive(currentFileName, firstLogEvent);
}

this.WriteToFile(currentFileName, ms.ToArray(), false);
this.WriteToFile(currentFileName, firstLogEvent, ms.ToArray(), false);
}
}
catch (Exception exception)
Expand Down Expand Up @@ -1528,15 +1528,15 @@ private byte[] GetFooterBytes()
*/
}

private void WriteToFile(string fileName, byte[] bytes, bool justData)
private void WriteToFile(string fileName, LogEventInfo logEvent, byte[] bytes, bool justData)
{
if (this.ReplaceFileContentsOnEachWrite)
{
ReplaceFileContent(fileName, bytes);
return;
}

bool writeHeader = InitializeFile(fileName, justData);
bool writeHeader = InitializeFile(fileName, logEvent, justData);
BaseFileAppender appender = AllocateFileAppender(fileName);

if (writeHeader)
Expand All @@ -1552,15 +1552,15 @@ private void WriteToFile(string fileName, byte[] bytes, bool justData)
}
}

private bool InitializeFile(string fileName, bool justData)
private bool InitializeFile(string fileName, LogEventInfo logEvent, bool justData)
{
bool writeHeader = false;

if (!justData)
{
if (!this.initializedFiles.ContainsKey(fileName))
{
ProcessOnStartup(fileName);
ProcessOnStartup(fileName, logEvent);

this.initializedFiles[fileName] = DateTime.Now;
this.initializedFilesCounter++;
Expand All @@ -1586,20 +1586,20 @@ private void WriteFooterAndUninitialize(string fileName)
{
if (File.Exists(fileName))
{
this.WriteToFile(fileName, footerBytes, true);
this.WriteToFile(fileName, null, footerBytes, true);
}
}

this.initializedFiles.Remove(fileName);
}

private void ProcessOnStartup(string fileName)
private void ProcessOnStartup(string fileName, LogEventInfo logEvent)
{
if (this.ArchiveOldFileOnStartup)
{
try
{
this.DoAutoArchive(fileName, null);
this.DoAutoArchive(fileName, logEvent);
}
catch (Exception exception)
{
Expand Down

0 comments on commit ca37ae5

Please sign in to comment.