@@ -256,7 +256,7 @@ protected internal override void OnConfigurationAssigned(LogFactory? logFactory)
256256
257257 if ( logFactory is null || ! AutoReload )
258258 {
259- if ( fileWatcher != null )
259+ if ( fileWatcher != null && ! fileWatcher . IsDisposed )
260260 {
261261 InternalLogger . Info ( "AutoReload Config File Monitor stopping, since no active configuration" ) ;
262262 fileWatcher . Dispose ( ) ;
@@ -661,11 +661,8 @@ private void ReloadTimer(object state)
661661 }
662662
663663 var currentTimer = _reloadTimer ;
664- if ( currentTimer != null )
665- {
666- _reloadTimer = null ;
667- currentTimer . Dispose ( ) ;
668- }
664+ _reloadTimer = null ;
665+ currentTimer ? . Dispose ( ) ;
669666 }
670667
671668 LoggingConfiguration ? newConfig = null ;
@@ -708,7 +705,6 @@ private void ReloadTimer(object state)
708705 {
709706 InternalLogger . Warn ( exception , "AutoReload Config File Monitor failed to activate new NLog LoggingConfiguration." ) ;
710707 _fileWatcher . Watch ( ( oldConfig as XmlLoggingConfiguration ) ? . AutoReloadFileNames ?? ArrayHelper . Empty < string > ( ) ) ;
711-
712708 }
713709 }
714710
@@ -719,14 +715,19 @@ public void RefreshFileWatcher(IEnumerable<string> fileNamesToWatch)
719715
720716 public void Dispose ( )
721717 {
722- _isDisposing = true ;
723- _fileWatcher . FileChanged -= FileWatcher_FileChanged ;
718+ var reloadTimer = _reloadTimer ;
724719 lock ( _lockObject )
725720 {
726- var reloadTimer = _reloadTimer ;
721+ if ( _isDisposing )
722+ return ;
723+
724+ reloadTimer = _reloadTimer ;
725+ _isDisposing = true ;
727726 _reloadTimer = null ;
728- reloadTimer ? . Dispose ( ) ;
729727 }
728+
729+ _fileWatcher . FileChanged -= FileWatcher_FileChanged ;
730+ reloadTimer ? . Dispose ( ) ;
730731 _fileWatcher . Dispose ( ) ;
731732 }
732733
0 commit comments