private void RefreshArchiveFilePatternToWatch()
{
#if !SILVERLIGHT && !__IOS__ && !__ANDROID__
if (this.fileAppenderCache != null)
{
bool mustWatchArchiving = IsArchivingEnabled() && ConcurrentWrites && KeepFileOpen;
if (mustWatchArchiving)
{
var nullEvent = LogEventInfo.CreateNullEvent();
string fileNamePattern = GetArchiveFileNamePattern(GetFullFileName(nullEvent), nullEvent);
if (!string.IsNullOrEmpty(fileNamePattern))
{
fileNamePattern = Path.Combine(Path.GetDirectoryName(fileNamePattern),
ReplaceFileNamePattern(fileNamePattern, "*"));
//fileNamePattern is absolute
this.fileAppenderCache.ArchiveFilePatternToWatch = fileNamePattern;
if ((EnableArchiveFileCompression) && (this.appenderInvalidatorThread == null))
{
// EnableArchiveFileCompression creates a new file for the archive, instead of just moving the log file.
// The log file is deleted instead of moved. This process may be holding a lock to that file which will
// avoid the file from being deleted. Therefore we must periodically close appenders for files that
// were archived so that the file can be deleted.
this.appenderInvalidatorThread = new Thread(() =>
{
while (true)
{
try
{
if (this.stopAppenderInvalidatorThreadWaitHandle.WaitOne(200))
break;
lock (SyncRoot)
{
this.fileAppenderCache.InvalidateAppendersForInvalidFiles();
}
}
catch (Exception ex)
{
InternalLogger.Debug(ex, "Exception in FileTarget appender-invalidator thread.");
}
}
});
this.appenderInvalidatorThread.IsBackground = true;
this.appenderInvalidatorThread.Start();
}
}
}
else
{
this.fileAppenderCache.ArchiveFilePatternToWatch = null;
this.StopAppenderInvalidatorThread();
}
}
#endif
}