123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using PCC2.EventBus;
- namespace PCC2.Logging;
- internal static class LoggingHolder
- {
- private static readonly List<LoggingEvent> _held = new();
- public static void Init(IAsyncEventBus eventBus) => eventBus.Subscript<LoggingEvent>(AddLog);
- private static Task AddLog(LoggingEvent obj)
- {
- lock (_held)
- {
- _held.Add(obj);
- }
- return Task.CompletedTask;
- }
- public static int Count
- {
- get
- {
- lock (_held)
- {
- return _held.Count;
- };
- }
- }
- public static IReadOnlyList<LoggingEvent> Get(LogLevel flags, int skip, int take)
- {
- IReadOnlyList<LoggingEvent> result;
- lock (_held)
- {
- result = _held.Where(p => flags.HasFlag(p.LogLevel)).Skip(skip).Take(take).ToArray();
- }
- return result;
- }
- public static void Clear()
- {
- lock (_held)
- {
- _held.Clear();
- }
- }
- }
|