aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/slskd/Program.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 9590ed48..f67a3a14 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -84,6 +84,11 @@ namespace slskd
public static readonly string XmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml");
/// <summary>
+ /// Occurs when a new log event is emitted.
+ /// </summary>
+ public static event EventHandler<LogEvent> LogEmitted;
+
+ /// <summary>
/// Gets the assembly version of the application.
/// </summary>
/// <remarks>
@@ -119,6 +124,11 @@ namespace slskd
/// </summary>
public static bool IsCanary { get; } = InformationalVersion.EndsWith("65534");
+ /// <summary>
+ /// Gets a buffer containing the last few log events.
+ /// </summary>
+ public static ConcurrentFixedSizeQueue<LogEvent> LogBuffer { get; } = new ConcurrentFixedSizeQueue<LogEvent>(size: 500);
+
private static IConfigurationRoot Configuration { get; set; }
private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup();
@@ -221,6 +231,11 @@ 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 =>