From 721d5cd25fb35a351ea0667fe5658075f71ba93d Mon Sep 17 00:00:00 2001 From: Madpeter Date: Tue, 13 Oct 2020 19:20:14 +0100 Subject: [PATCH] Update Log2FileBot.cs --- Core/bottypes/Log2FileBot.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Core/bottypes/Log2FileBot.cs b/Core/bottypes/Log2FileBot.cs index 4ad7414..040f1ed 100644 --- a/Core/bottypes/Log2FileBot.cs +++ b/Core/bottypes/Log2FileBot.cs @@ -37,7 +37,9 @@ namespace BSB.bottypes var logFolderPath = LogFolderName; if (!Directory.Exists(logFolderPath)) - Directory.CreateDirectory(logFolderPath); + { + Directory.CreateDirectory(logFolderPath); + } var logFilePath = Path.Combine(logFolderPath, LogFileName); @@ -52,11 +54,15 @@ namespace BSB.bottypes private void Rotate(string filePath) { if (!File.Exists(filePath)) + { return; + } var fileInfo = new FileInfo(filePath); if (fileInfo.Length < _logChunkSize) + { return; + } var fileTime = DateTime.Now.ToString("dd_MM_yy_h_m_s"); var rotatedPath = filePath.Replace(".log", $".{fileTime}"); @@ -68,7 +74,9 @@ namespace BSB.bottypes var chunks = logFolderContent.Where(x => !x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)); if (chunks.Count() <= _logChunkMaxCount) + { return; + } var archiveFolderInfo = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(rotatedPath), $"{LogFolderName}_{fileTime}")); @@ -83,7 +91,9 @@ namespace BSB.bottypes var archives = logFolderContent.Where(x => x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)).ToArray(); if (archives.Count() <= _logArchiveMaxCount) + { return; + } var oldestArchive = archives.OrderBy(x => x.CreationTime).First(); var cleanupDate = oldestArchive.CreationTime.AddDays(_logCleanupPeriod); @@ -95,7 +105,9 @@ namespace BSB.bottypes } } else + { File.Delete(oldestArchive.FullName); + } } }