using System;
using System.Collections.Generic;
using System.Linq;
using Serilog.Events;
namespace Artemis.Core;
///
/// A static store containing the last 500 logging events
///
public static class LogStore
{
private static readonly object _lock = new();
private static readonly LinkedList LinkedList = new();
///
/// Gets a list containing the last 500 log events.
///
public static List Events
{
get
{
List events;
lock (_lock)
events = LinkedList.ToList();
return events;
}
}
///
/// Occurs when a new was received.
///
public static event EventHandler? EventAdded;
internal static void Emit(LogEvent logEvent)
{
lock (_lock)
{
LinkedList.AddLast(logEvent);
while (LinkedList.Count > 500)
LinkedList.RemoveFirst();
}
OnEventAdded(new LogEventEventArgs(logEvent));
}
private static void OnEventAdded(LogEventEventArgs e)
{
EventAdded?.Invoke(null, e);
}
}
///
/// Contains log event related data
///
public class LogEventEventArgs : EventArgs
{
internal LogEventEventArgs(LogEvent logEvent)
{
LogEvent = logEvent;
}
///
/// Gets the log event
///
public LogEvent LogEvent { get; }
}