feat: Initial implementation of DebugWebsocketSink

This commit is contained in:
Neil Dorin
2023-10-30 17:24:47 -06:00
parent 6174400b7e
commit 2f1180512c
5 changed files with 141 additions and 7 deletions

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Configuration;
using WebSocketSharp.Server;
namespace PepperDash.Core
{
public class DebugWebsocketSink : ILogEventSink
{
public WebSocketServer WSSV { get; private set; }
private readonly IFormatProvider _formatProvider;
public DebugWebsocketSink()
{
WSSV = new WebSocketServer();
}
public void Emit(LogEvent logEvent)
{
var message = logEvent.RenderMessage(_formatProvider);
WSSV.WebSocketServices.Broadcast(message);
}
}
public static class DebugWebsocketSinkExtensions
{
public static LoggerConfiguration DebugWebsocketSink(
this LoggerSinkConfiguration loggerConfiguration,
IFormatProvider formatProvider = null)
{
return loggerConfiguration.Sink(new DebugWebsocketSink());
}
}
}