From 96a7f141ff6b6adefb2ef8af668d5ac125692e54 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 4 Oct 2021 18:51:19 -0500 Subject: configure LogBuffer and LogEmitted --- src/slskd/Program.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') 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 @@ -83,6 +83,11 @@ namespace slskd /// public static readonly string XmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml"); + /// + /// Occurs when a new log event is emitted. + /// + public static event EventHandler LogEmitted; + /// /// Gets the assembly version of the application. /// @@ -119,6 +124,11 @@ namespace slskd /// public static bool IsCanary { get; } = InformationalVersion.EndsWith("65534"); + /// + /// Gets a buffer containing the last few log events. + /// + public static ConcurrentFixedSizeQueue LogBuffer { get; } = new ConcurrentFixedSizeQueue(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 => -- cgit v1.2.3