diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-10-04 18:51:19 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-10-04 18:51:19 -0500 |
| commit | 96a7f141ff6b6adefb2ef8af668d5ac125692e54 (patch) | |
| tree | 7c699c65683560c58d8aa3f7be861760ae0c9c99 /src/slskd/Program.cs | |
| parent | f94744408cac94ffe096d4c5e7b646d37a52291d (diff) | |
| download | slskd-96a7f141ff6b6adefb2ef8af668d5ac125692e54.tar.gz | |
configure LogBuffer and LogEmitted
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 15 |
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 => |
