Commit 63d6d367 authored by AntekZ's avatar AntekZ

compression removed, rotate files at 2MB instead of 20MB

parent 42775126
...@@ -73,7 +73,7 @@ namespace LcdLogger.Services ...@@ -73,7 +73,7 @@ namespace LcdLogger.Services
return Task.CompletedTask; return Task.CompletedTask;
} }
var files = DirectoryInfo.GetFiles("lcd-*.log*").OrderBy(f => f.Name).ToList(); var files = DirectoryInfo.GetFiles("lcd-*.log").OrderBy(f => f.Name).ToList();
long totalBytes = files.Sum(f => f.Length); long totalBytes = files.Sum(f => f.Length);
...@@ -108,35 +108,35 @@ namespace LcdLogger.Services ...@@ -108,35 +108,35 @@ namespace LcdLogger.Services
var justClosedFile = _currentPath; var justClosedFile = _currentPath;
_ = Task.Run(async () => //_ = Task.Run(async () =>
{ //{
await CompressAsync(justClosedFile); // await CompressAsync(justClosedFile);
}); //});
await PruneSurplusFilesAsync(cancellationToken); await PruneSurplusFilesAsync(cancellationToken);
await OpenNewAsync(cancellationToken); await OpenNewAsync(cancellationToken);
} }
private async Task CompressAsync(string path) //private async Task CompressAsync(string path)
{ //{
try // try
{ // {
var gzPath = path + ".gz"; // var gzPath = path + ".gz";
using (var source = File.OpenRead(path)) // using (var source = File.OpenRead(path))
using (var destination = File.Create(gzPath)) // using (var destination = File.Create(gzPath))
using (var gzip = new GZipStream(destination, CompressionLevel.SmallestSize)) // using (var gzip = new GZipStream(destination, CompressionLevel.SmallestSize))
{ // {
await source.CopyToAsync(gzip); // await source.CopyToAsync(gzip);
} // }
File.Delete(path); // File.Delete(path);
} // }
catch (Exception e) // catch (Exception e)
{ // {
_logger.LogError(e.Message, "Compress failed"); // _logger.LogError(e.Message, "Compress failed");
} // }
} //}
public async ValueTask DisposeAsync() public async ValueTask DisposeAsync()
{ {
......
{ {
"Log": { "Log": {
"Directory": "/var/log/lcd-logger", "Directory": "/var/log/lcd-logger",
"RotateAtBytes": 20971520, "RotateAtBytes": 2097152,
"MaxTotalBytes": 104857600, "MaxTotalBytes": 104857600,
"MinLevel": 2, "MinLevel": 2,
"MaxBatchEntries": 100, "MaxBatchEntries": 100,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment