mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 05:47:28 +02:00
Version 3.0.337
This commit is contained in:
parent
fd0e63cf10
commit
573fe77e12
2336 changed files with 33688 additions and 86082 deletions
47
TINKLib/Services/Logging/MemoryStackSink.cs
Normal file
47
TINKLib/Services/Logging/MemoryStackSink.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace TINK.Services.Logging
|
||||
{
|
||||
public class MemoryStackSink : ILogEventSink
|
||||
{
|
||||
private readonly IFormatProvider _formatProvider;
|
||||
|
||||
private static ConcurrentStack<string> _MessageStack = new ConcurrentStack<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Reads all messages an clears memory stack.
|
||||
/// </summary>
|
||||
/// <returns>Array of messages.</returns>
|
||||
public static string[] PopAllMessages()
|
||||
{
|
||||
int countOfMessages = _MessageStack.Count;
|
||||
if (countOfMessages <= 0)
|
||||
return new string[0];
|
||||
|
||||
string[] messages = new string[countOfMessages];
|
||||
if (_MessageStack.TryPopRange(messages) <= 0)
|
||||
return new string[0];
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the message stack.
|
||||
/// </summary>
|
||||
public static void ClearMessages() => _MessageStack.Clear();
|
||||
|
||||
public MemoryStackSink(IFormatProvider formatProvider)
|
||||
{
|
||||
_formatProvider = formatProvider;
|
||||
}
|
||||
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
var message = logEvent.RenderMessage(_formatProvider);
|
||||
_MessageStack.Push(DateTimeOffset.Now.ToString() + " " + message);
|
||||
}
|
||||
}
|
||||
}
|
16
TINKLib/Services/Logging/MemoryStackSinkExtensions.cs
Normal file
16
TINKLib/Services/Logging/MemoryStackSinkExtensions.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using Serilog;
|
||||
using Serilog.Configuration;
|
||||
|
||||
namespace TINK.Services.Logging
|
||||
{
|
||||
public static class MemoryStackSinkExtensions
|
||||
{
|
||||
public static LoggerConfiguration MemoryQueueSink(
|
||||
this LoggerSinkConfiguration loggerConfiguration,
|
||||
IFormatProvider formatProvider = null)
|
||||
{
|
||||
return loggerConfiguration.Sink(new MemoryStackSink(formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue