Updated
This commit is contained in:
@@ -14,7 +14,7 @@ It features a rich fluent API for routing log events to dozens of destinations f
|
|||||||
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
<Copyright>EonaCat (Jeroen Saey)</Copyright>
|
||||||
<PackageTags>EonaCat;Logger;EonaCatLogStack;Log;Writer;Flows;LogStack;Memory;Speed;Jeroen;Saey</PackageTags>
|
<PackageTags>EonaCat;Logger;EonaCatLogStack;Log;Writer;Flows;LogStack;Memory;Speed;Jeroen;Saey</PackageTags>
|
||||||
<PackageIconUrl />
|
<PackageIconUrl />
|
||||||
<FileVersion>0.0.4</FileVersion>
|
<FileVersion>0.0.5</FileVersion>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
@@ -25,7 +25,7 @@ It features a rich fluent API for routing log events to dozens of destinations f
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<EVRevisionFormat>0.0.4+{chash:10}.{c:ymd}</EVRevisionFormat>
|
<EVRevisionFormat>0.0.5+{chash:10}.{c:ymd}</EVRevisionFormat>
|
||||||
<EVDefault>true</EVDefault>
|
<EVDefault>true</EVDefault>
|
||||||
<EVInfo>true</EVInfo>
|
<EVInfo>true</EVInfo>
|
||||||
<EVTagMatch>v[0-9]*</EVTagMatch>
|
<EVTagMatch>v[0-9]*</EVTagMatch>
|
||||||
@@ -36,7 +36,7 @@ It features a rich fluent API for routing log events to dozens of destinations f
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>0.0.4</Version>
|
<Version>0.0.5</Version>
|
||||||
<PackageId>EonaCat.LogStack</PackageId>
|
<PackageId>EonaCat.LogStack</PackageId>
|
||||||
<Product>EonaCat.LogStack</Product>
|
<Product>EonaCat.LogStack</Product>
|
||||||
<RepositoryUrl>https://git.saey.me/EonaCat/EonaCat.LogStack</RepositoryUrl>
|
<RepositoryUrl>https://git.saey.me/EonaCat/EonaCat.LogStack</RepositoryUrl>
|
||||||
|
|||||||
@@ -1732,6 +1732,38 @@ namespace EonaCat.LogStack.Flows
|
|||||||
|
|
||||||
// Delete the original uncompressed file after successful compression
|
// Delete the original uncompressed file after successful compression
|
||||||
try { File.Delete(path); } catch { /* ignore */ }
|
try { File.Delete(path); } catch { /* ignore */ }
|
||||||
|
|
||||||
|
EnforceCompressedFileLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EnforceCompressedFileLimit()
|
||||||
|
{
|
||||||
|
if (_retention.MaxCompressedFiles <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DirectoryInfo dir = new DirectoryInfo(_directory);
|
||||||
|
if (!dir.Exists)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInfo[] compressedFiles = dir.GetFiles("*" + _fileExtension + ".gz")
|
||||||
|
.OrderByDescending(f => f.LastWriteTimeUtc)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
for (int i = _retention.MaxCompressedFiles; i < compressedFiles.Length; i++)
|
||||||
|
{
|
||||||
|
try { compressedFiles[i].Delete(); } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
WriteToConsoleError("[FileFlow] Compressed retention error: " + ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PeriodicFlushLoop()
|
private void PeriodicFlushLoop()
|
||||||
@@ -1796,17 +1828,22 @@ namespace EonaCat.LogStack.Flows
|
|||||||
|
|
||||||
long totalBytes = 0;
|
long totalBytes = 0;
|
||||||
int kept = 0;
|
int kept = 0;
|
||||||
|
int keptCompressed = 0;
|
||||||
|
|
||||||
foreach (FileInfo f in files)
|
foreach (FileInfo f in files)
|
||||||
{
|
{
|
||||||
|
bool isCompressed = f.Extension.Equals(".gz", StringComparison.OrdinalIgnoreCase);
|
||||||
bool tooOld = _retention.MaxAgeDays > 0
|
bool tooOld = _retention.MaxAgeDays > 0
|
||||||
&& (DateTime.UtcNow - f.LastWriteTimeUtc).TotalDays > _retention.MaxAgeDays;
|
&& (DateTime.UtcNow - f.LastWriteTimeUtc).TotalDays > _retention.MaxAgeDays;
|
||||||
bool tooMany = _retention.MaxRolledFiles > 0 && kept >= _retention.MaxRolledFiles;
|
bool tooMany = _retention.MaxRolledFiles > 0 && kept >= _retention.MaxRolledFiles;
|
||||||
|
bool tooManyCompressed = isCompressed
|
||||||
|
&& _retention.MaxCompressedFiles > 0
|
||||||
|
&& keptCompressed >= _retention.MaxCompressedFiles;
|
||||||
bool tooLarge = _retention.MaxTotalArchiveBytes > 0
|
bool tooLarge = _retention.MaxTotalArchiveBytes > 0
|
||||||
&& totalBytes + f.Length > _retention.MaxTotalArchiveBytes;
|
&& totalBytes + f.Length > _retention.MaxTotalArchiveBytes;
|
||||||
bool directoryTooLarge = totalBytes + f.Length > _maxDirectorySize;
|
bool directoryTooLarge = totalBytes + f.Length > _maxDirectorySize;
|
||||||
|
|
||||||
if (tooOld || tooMany || tooLarge || directoryTooLarge)
|
if (tooOld || tooMany || tooManyCompressed || tooLarge || directoryTooLarge)
|
||||||
{
|
{
|
||||||
try { f.Delete(); } catch { /* ignore */ }
|
try { f.Delete(); } catch { /* ignore */ }
|
||||||
}
|
}
|
||||||
@@ -1814,6 +1851,10 @@ namespace EonaCat.LogStack.Flows
|
|||||||
{
|
{
|
||||||
totalBytes += f.Length;
|
totalBytes += f.Length;
|
||||||
kept++;
|
kept++;
|
||||||
|
if (isCompressed)
|
||||||
|
{
|
||||||
|
keptCompressed++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ namespace EonaCat.LogStack.EonaCatLogStackCore.Policies
|
|||||||
/// <summary>Maximum number of rolled archive files to keep (0 = unlimited).</summary>
|
/// <summary>Maximum number of rolled archive files to keep (0 = unlimited).</summary>
|
||||||
public int MaxRolledFiles { get; set; }
|
public int MaxRolledFiles { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Maximum number of compressed .gz files to keep (0 = unlimited).</summary>
|
||||||
|
public int MaxCompressedFiles { get; set; }
|
||||||
|
|
||||||
/// <summary>Maximum total size of all archives in bytes (0 = unlimited).</summary>
|
/// <summary>Maximum total size of all archives in bytes (0 = unlimited).</summary>
|
||||||
public long MaxTotalArchiveBytes { get; set; }
|
public long MaxTotalArchiveBytes { get; set; }
|
||||||
|
|
||||||
@@ -18,6 +21,7 @@ namespace EonaCat.LogStack.EonaCatLogStackCore.Policies
|
|||||||
public FileRetentionPolicy()
|
public FileRetentionPolicy()
|
||||||
{
|
{
|
||||||
MaxRolledFiles = 10;
|
MaxRolledFiles = 10;
|
||||||
|
MaxCompressedFiles = 5;
|
||||||
MaxTotalArchiveBytes = 0;
|
MaxTotalArchiveBytes = 0;
|
||||||
MaxAgeDays = 0;
|
MaxAgeDays = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user