protected override void Dispose(bool disposing) { if (disposing) { _isDisposing = true; if (_watcher != null) { // Disable startup of new reload-timers _watcher.FileChanged -= ConfigFileChanged; _watcher.StopWatching(); } var currentTimer = _reloadTimer; if (currentTimer != null) { _reloadTimer = null; currentTimer.WaitForDispose(TimeSpan.Zero); } // Dispose file-watcher after having dispose timer to avoid race _watcher?.Dispose(); } base.Dispose(disposing); }
private void CloseAppender(BaseFileAppender appender) { appender.Close(); #if !SILVERLIGHT && !__IOS__ && !__ANDROID__ externalFileArchivingWatcher.StopWatching(); #endif }
private void CloseAppender(BaseFileAppender appender, string reason, bool lastAppender) { InternalLogger.Debug("FileAppender Closing {0} - {1}", reason, appender.FileName); if (lastAppender) { // No active appenders, deactivate background tasks autoClosingTimer.Change(Timeout.Infinite, Timeout.Infinite); #if !SILVERLIGHT && !__IOS__ && !__ANDROID__ externalFileArchivingWatcher.StopWatching(); logFileWasArchived = false; } else { externalFileArchivingWatcher.StopWatching(appender.FileName); #endif } appender.Close(); }
private void TryUnwatchConfigFile() { try { _watcher?.StopWatching(); } catch (Exception exception) { InternalLogger.Error(exception, "Cannot stop file watching."); if (exception.MustBeRethrown()) { throw; } } }
internal void ReloadConfigOnTimer(object state) { LoggingConfiguration configurationToReload = (LoggingConfiguration)state; InternalLogger.Info("Reloading configuration..."); lock (this) { if (_reloadTimer != null) { _reloadTimer.Dispose(); _reloadTimer = null; } _watcher.StopWatching(); try { if (Configuration != configurationToReload) { throw new Exception("Config changed in between. Not reloading."); } LoggingConfiguration newConfig = configurationToReload.Reload(); if (newConfig != null) { Configuration = newConfig; if (ConfigurationReloaded != null) { ConfigurationReloaded(true, null); } } else { throw new Exception("Configuration.Reload() returned null. Not reloading."); } } catch (Exception ex) { _watcher.Watch(configurationToReload.FileNamesToWatch); if (ConfigurationReloaded != null) { ConfigurationReloaded(false, ex); } } } }