@@ -336,23 +336,30 @@ private void CleanupOldImages()
336
336
_logger . LogInformation ( $ "Captures Clean Up: Cleaning up images older than { Config . DaysToKeepCaptures } day(s).") ;
337
337
Task . Run ( ( ) =>
338
338
{
339
- lock ( _cleanUpOldImagesLock )
339
+ try
340
340
{
341
- _cleanupOldImagesRunning = true ;
342
-
343
- DirectoryInfo directory = new ( Constants . DIRECTORY_CAPTURES ) ;
344
- IEnumerable < FileInfo > files = directory . GetFiles ( "*" , new EnumerationOptions ( ) { RecurseSubdirectories = true } ) ;
345
- foreach ( FileInfo file in files )
341
+ lock ( _cleanUpOldImagesLock )
346
342
{
347
- double age = ( DateTime . Now - file . CreationTime ) . TotalDays ;
348
- if ( age > Config . DaysToKeepCaptures )
343
+ _cleanupOldImagesRunning = true ;
344
+
345
+ DirectoryInfo directory = new ( Constants . DIRECTORY_CAPTURES ) ;
346
+ IEnumerable < FileInfo > files = directory . GetFiles ( "*" , new EnumerationOptions ( ) { RecurseSubdirectories = true } ) ;
347
+ foreach ( FileInfo file in files )
349
348
{
350
- _logger . LogInformation ( $ "Captures Clean Up: { file . FullName } is { age } day(s) old and will be deleted.") ;
351
- System . IO . File . Delete ( file . FullName ) ;
352
- _logger . LogInformation ( $ "Captures Clean Up: { file . FullName } deleted.") ;
349
+ double age = ( DateTime . Now - file . CreationTime ) . TotalDays ;
350
+ if ( age > Config . DaysToKeepCaptures )
351
+ {
352
+ _logger . LogInformation ( $ "Captures Clean Up: { file . FullName } is { age } day(s) old and will be deleted.") ;
353
+ System . IO . File . Delete ( file . FullName ) ;
354
+ _logger . LogInformation ( $ "Captures Clean Up: { file . FullName } deleted.") ;
355
+ }
353
356
}
357
+ _cleanupOldImagesRunning = false ;
354
358
}
355
- _cleanupOldImagesRunning = false ;
359
+ }
360
+ catch ( Exception ex )
361
+ {
362
+ _logger . LogError ( ex , "Captures Clean Up Failed" ) ;
356
363
}
357
364
} ) ;
358
365
}
0 commit comments