aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-10-05 08:25:07 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-10-05 08:25:07 -0500
commit3feb7bb0a39719744cdacc64047c95e5d5808c17 (patch)
tree02960bcd64cd9cec075997c2e588238aa2ec6010 /src/slskd/Program.cs
parentfd6f8adfdbae8769c484416ff6ef80b5a4781f12 (diff)
downloadslskd-3feb7bb0a39719744cdacc64047c95e5d5808c17.tar.gz
store LogRecords instead of LogEvents
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index f67a3a14..b5e628cc 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -86,7 +86,7 @@ namespace slskd
/// <summary>
/// Occurs when a new log event is emitted.
/// </summary>
- public static event EventHandler<LogEvent> LogEmitted;
+ public static event EventHandler<LogRecord> LogEmitted;
/// <summary>
/// Gets the assembly version of the application.
@@ -127,7 +127,7 @@ namespace slskd
/// <summary>
/// Gets a buffer containing the last few log events.
/// </summary>
- public static ConcurrentFixedSizeQueue<LogEvent> LogBuffer { get; } = new ConcurrentFixedSizeQueue<LogEvent>(size: 500);
+ public static ConcurrentFixedSizeQueue<LogRecord> LogBuffer { get; } = new ConcurrentFixedSizeQueue<LogRecord>(size: 500);
private static IConfigurationRoot Configuration { get; set; }
private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup();
@@ -231,11 +231,6 @@ namespace slskd
.Enrich.WithProperty("InvocationId", InvocationId)
.Enrich.WithProperty("ProcessId", ProcessId)
.Enrich.FromLogContext()
- .WriteTo.Sink(new DelegatingSink(logEvent =>
- {
- LogBuffer.Enqueue(logEvent);
- LogEmitted?.Invoke(null, logEvent);
- }))
.WriteTo.Console(
outputTemplate: (OptionsAtStartup.Debug ? "[{SourceContext}] [{SoulseekContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Async(config =>
@@ -248,6 +243,19 @@ namespace slskd
config => config.GrafanaLoki(
OptionsAtStartup.Logger.Loki ?? string.Empty,
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"))
+ .WriteTo.Sink(new DelegatingSink(logEvent =>
+ {
+ var record = new LogRecord()
+ {
+ Timestamp = logEvent.Timestamp.LocalDateTime,
+ Context = logEvent.Properties["SourceContext"].ToString().TrimStart('"').TrimEnd('"'),
+ Level = logEvent.Level.ToString(),
+ Message = logEvent.RenderMessage().TrimStart('"').TrimEnd('"'),
+ };
+
+ LogBuffer.Enqueue(record);
+ LogEmitted?.Invoke(null, record);
+ }))
.CreateLogger();
var logger = Log.ForContext(typeof(Program));