mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-14 04:04:47 +00:00
feat: Initial implementation of DebugWebsocketSink
This commit is contained in:
42
src/Pepperdash Core/Logging/DebugWebsocketSink.cs
Normal file
42
src/Pepperdash Core/Logging/DebugWebsocketSink.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user