Update Log2FileBot.cs
This commit is contained in:
parent
dfc4d746c6
commit
721d5cd25f
1 changed files with 13 additions and 1 deletions
|
|
@ -37,7 +37,9 @@ namespace BSB.bottypes
|
||||||
var logFolderPath = LogFolderName;
|
var logFolderPath = LogFolderName;
|
||||||
|
|
||||||
if (!Directory.Exists(logFolderPath))
|
if (!Directory.Exists(logFolderPath))
|
||||||
Directory.CreateDirectory(logFolderPath);
|
{
|
||||||
|
Directory.CreateDirectory(logFolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
var logFilePath = Path.Combine(logFolderPath, LogFileName);
|
var logFilePath = Path.Combine(logFolderPath, LogFileName);
|
||||||
|
|
||||||
|
|
@ -52,11 +54,15 @@ namespace BSB.bottypes
|
||||||
private void Rotate(string filePath)
|
private void Rotate(string filePath)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var fileInfo = new FileInfo(filePath);
|
var fileInfo = new FileInfo(filePath);
|
||||||
if (fileInfo.Length < _logChunkSize)
|
if (fileInfo.Length < _logChunkSize)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var fileTime = DateTime.Now.ToString("dd_MM_yy_h_m_s");
|
var fileTime = DateTime.Now.ToString("dd_MM_yy_h_m_s");
|
||||||
var rotatedPath = filePath.Replace(".log", $".{fileTime}");
|
var rotatedPath = filePath.Replace(".log", $".{fileTime}");
|
||||||
|
|
@ -68,7 +74,9 @@ namespace BSB.bottypes
|
||||||
var chunks = logFolderContent.Where(x => !x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase));
|
var chunks = logFolderContent.Where(x => !x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (chunks.Count() <= _logChunkMaxCount)
|
if (chunks.Count() <= _logChunkMaxCount)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var archiveFolderInfo = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(rotatedPath), $"{LogFolderName}_{fileTime}"));
|
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();
|
var archives = logFolderContent.Where(x => x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||||
|
|
||||||
if (archives.Count() <= _logArchiveMaxCount)
|
if (archives.Count() <= _logArchiveMaxCount)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var oldestArchive = archives.OrderBy(x => x.CreationTime).First();
|
var oldestArchive = archives.OrderBy(x => x.CreationTime).First();
|
||||||
var cleanupDate = oldestArchive.CreationTime.AddDays(_logCleanupPeriod);
|
var cleanupDate = oldestArchive.CreationTime.AddDays(_logCleanupPeriod);
|
||||||
|
|
@ -95,7 +105,9 @@ namespace BSB.bottypes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
File.Delete(oldestArchive.FullName);
|
File.Delete(oldestArchive.FullName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue