Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIxed ArchiveOldFileOnStartup with layout renderer used in ArchiveFileName #774

Merged
merged 1 commit into from
Jul 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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