Commit 42775126 authored by Antoni Zaprzała's avatar Antoni Zaprzała

small changes

parent 8187443f
@LcdLogger_HostAddress = http://localhost:5194
GET {{LcdLogger_HostAddress}}/weatherforecast/
Accept: application/json
###
...@@ -6,13 +6,11 @@ namespace LcdLogger.Models ...@@ -6,13 +6,11 @@ namespace LcdLogger.Models
public sealed class LogEntry public sealed class LogEntry
{ {
[JsonPropertyName("timestamp")] [JsonPropertyName("timestamp")]
public long TimeStamp { get; set; } public string TimeStamp { get; set; } = "";
//log level
[JsonPropertyName("level")] [JsonPropertyName("level")]
public int Level { get; set; } public int Level { get; set; }
//service name/ component name that logged
[JsonPropertyName("source")] [JsonPropertyName("source")]
public string Source { get; set; } = ""; public string Source { get; set; } = "";
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
public long RotateAtBytes { get; set; } = 20971520; public long RotateAtBytes { get; set; } = 20971520;
public long MaxTotalBytes { get; set; } = 104857600; public long MaxTotalBytes { get; set; } = 104857600;
public int MinLevel { get; set; } = 2; public int MinLevel { get; set; } = 2;
public int FlushEveryMs { get; set; } = 500;
public int MaxBatchEntries { get; set; } = 100; public int MaxBatchEntries { get; set; } = 100;
public int QueueCapacity { get; set; } = 250; public int QueueCapacity { get; set; } = 250;
......
...@@ -10,9 +10,8 @@ builder.Services.AddHostedService<LogWorker>(); ...@@ -10,9 +10,8 @@ builder.Services.AddHostedService<LogWorker>();
var app = builder.Build(); var app = builder.Build();
//sprawdzenie uzywanych appsettingsow przez serwis - moze useless i wywalic idk //app.MapGet("/debug/options", (IOptions<LogOptions> options) =>
app.MapGet("/debug/options", (IOptions<LogOptions> options) => // Results.Ok(options.Value));
Results.Ok(options.Value));
app.MapPost("/logs", (LogBatch batch, LogQueue queue, IOptions<LogOptions> opts) => app.MapPost("/logs", (LogBatch batch, LogQueue queue, IOptions<LogOptions> opts) =>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
"launchBrowser": false, "launchBrowser": false,
"applicationUrl": "http://localhost:5194", "applicationUrl": "http://localhost:5194",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
} }
}, },
"https": { "https": {
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"launchBrowser": false, "launchBrowser": false,
"applicationUrl": "https://localhost:7291;http://localhost:5194", "applicationUrl": "https://localhost:7291;http://localhost:5194",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
} }
} }
} }
......
...@@ -25,14 +25,14 @@ namespace LcdLogger.Services ...@@ -25,14 +25,14 @@ namespace LcdLogger.Services
{ {
Directory.CreateDirectory(_options.Directory); Directory.CreateDirectory(_options.Directory);
await PruneOldFilesAsync(cancellationToken); await PruneSurplusFilesAsync(cancellationToken);
await OpenNewAsync(cancellationToken); await OpenNewAsync(cancellationToken);
} }
private Task OpenNewAsync(CancellationToken cancellationToken = default) private Task OpenNewAsync(CancellationToken cancellationToken = default)
{ {
var timestamp = DateTime.UtcNow.ToString("yyyyMMddTHHmmssfffZ"); var timestamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
_currentPath = Path.Combine(_options.Directory, $"lcd-{timestamp}.log"); _currentPath = Path.Combine(_options.Directory, $"lcd-{timestamp}.log");
_fileStream = new FileStream(_currentPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferSize: 1, useAsync: true); _fileStream = new FileStream(_currentPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferSize: 1, useAsync: true);
_size = 0; _size = 0;
...@@ -46,7 +46,11 @@ namespace LcdLogger.Services ...@@ -46,7 +46,11 @@ namespace LcdLogger.Services
{ {
if (entry.Level < _options.MinLevel) continue; if (entry.Level < _options.MinLevel) continue;
var bytes = JsonSerializer.SerializeToUtf8Bytes(entry); //var bytes = JsonSerializer.SerializeToUtf8Bytes(entry);
var bytes = JsonSerializer.SerializeToUtf8Bytes(entry, new JsonSerializerOptions
{
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
});
await _fileStream.WriteAsync(bytes, cancellationToken); await _fileStream.WriteAsync(bytes, cancellationToken);
await _fileStream.WriteAsync(_newline, cancellationToken); await _fileStream.WriteAsync(_newline, cancellationToken);
...@@ -60,7 +64,7 @@ namespace LcdLogger.Services ...@@ -60,7 +64,7 @@ namespace LcdLogger.Services
} }
} }
private Task PruneOldFilesAsync(CancellationToken cancellationToken = default) private Task PruneSurplusFilesAsync(CancellationToken cancellationToken = default)
{ {
var DirectoryInfo = new DirectoryInfo(_options.Directory); var DirectoryInfo = new DirectoryInfo(_options.Directory);
if(!DirectoryInfo.Exists) if(!DirectoryInfo.Exists)
...@@ -109,7 +113,7 @@ namespace LcdLogger.Services ...@@ -109,7 +113,7 @@ namespace LcdLogger.Services
await CompressAsync(justClosedFile); await CompressAsync(justClosedFile);
}); });
await PruneOldFilesAsync(cancellationToken); await PruneSurplusFilesAsync(cancellationToken);
await OpenNewAsync(cancellationToken); await OpenNewAsync(cancellationToken);
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogError(e, "Failed to write batch with {Count} entries", batch.Logs.Length); _logger.LogError("Failed to write batch {e}", e);
} }
} }
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
"RotateAtBytes": 20971520, "RotateAtBytes": 20971520,
"MaxTotalBytes": 104857600, "MaxTotalBytes": 104857600,
"MinLevel": 2, "MinLevel": 2,
"FlushEveryMs": 500,
"MaxBatchEntries": 100, "MaxBatchEntries": 100,
"QueueCapacity": 250 "QueueCapacity": 250
}, },
......
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