mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Merge branch 'development' into vulkan
This commit is contained in:
commit
fc9476247f
12 files changed
+502
-112
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ninject.Activation;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
@@ -17,6 +18,7 @@ namespace Artemis.Core.Ninject
|
||||
rollingInterval: RollingInterval.Day,
|
||||
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}")
|
||||
.WriteTo.Debug()
|
||||
.WriteTo.Sink<ArtemisSink>()
|
||||
.MinimumLevel.ControlledBy(LoggingLevelSwitch)
|
||||
.CreateLogger();
|
||||
|
||||
@@ -28,4 +30,13 @@ namespace Artemis.Core.Ninject
|
||||
return Logger;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ArtemisSink : ILogEventSink
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
LogStore.Emit(logEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A static store containing the last 500 logging events
|
||||
/// </summary>
|
||||
public static class LogStore
|
||||
{
|
||||
private static readonly LinkedList<LogEvent> LinkedList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing the last 500 log events.
|
||||
/// </summary>
|
||||
public static List<LogEvent> Events => LinkedList.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a new <see cref="LogEvent" /> was received.
|
||||
/// </summary>
|
||||
public static event EventHandler<LogEventEventArgs>? EventAdded;
|
||||
|
||||
internal static void Emit(LogEvent logEvent)
|
||||
{
|
||||
LinkedList.AddLast(logEvent);
|
||||
if (LinkedList.Count > 500)
|
||||
LinkedList.RemoveFirst();
|
||||
|
||||
OnEventAdded(new LogEventEventArgs(logEvent));
|
||||
}
|
||||
|
||||
private static void OnEventAdded(LogEventEventArgs e)
|
||||
{
|
||||
EventAdded?.Invoke(null, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains log event related data
|
||||
/// </summary>
|
||||
public class LogEventEventArgs : EventArgs
|
||||
{
|
||||
internal LogEventEventArgs(LogEvent logEvent)
|
||||
{
|
||||
LogEvent = logEvent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the log event
|
||||
/// </summary>
|
||||
public LogEvent LogEvent { get; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user