You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Trash/LogJanitor.cs

26 lines
634 B

using System.IO.Abstractions;
using System.Linq;
namespace Trash
{
public class LogJanitor : ILogJanitor
{
private readonly IFileSystem _fileSystem;
public LogJanitor(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
public void DeleteOldestLogFiles(int numberOfNewestToKeep)
{
foreach (var file in _fileSystem.DirectoryInfo.FromDirectoryName(AppPaths.LogDirectory).GetFiles()
.OrderByDescending(f => f.Name)
.Skip(numberOfNewestToKeep))
{
file.Delete();
}
}
}
}