aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorExouxas <exouxas@gmail.com>2021-10-07 19:58:17 +0200
committerGitHub <noreply@github.com>2021-10-07 19:58:17 +0200
commit4a2e443b545698466db86395fa142b84d717b450 (patch)
treeb5015d00172d4baa7d25b3362ccbd14f6a6de354 /src/slskd/Program.cs
parent3868570c571a631773c065ddad470c8077a5869e (diff)
parent228cd7f97761137bde191d45c1771879a8d45de3 (diff)
downloadslskd-4a2e443b545698466db86395fa142b84d717b450.tar.gz
Merge branch 'master' into master
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 5690051b..2646a780 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<LogRecord> 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<LogRecord> LogBuffer { get; } = new ConcurrentFixedSizeQueue<LogRecord>(size: 500);
+
private static IConfigurationRoot Configuration { get; set; }
private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup();
@@ -245,6 +255,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));