mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 05:04:48 +00:00
fix: adds text formatter
This commit is contained in:
@@ -11,6 +11,7 @@ using PepperDash.Core.DebugThings;
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
using Serilog.Formatting.Compact;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
@@ -106,7 +107,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
_consoleLoggingLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: LogEventLevel.Information);
|
_consoleLoggingLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: LogEventLevel.Information);
|
||||||
_websocketLoggingLevelSwitch = new LoggingLevelSwitch();
|
_websocketLoggingLevelSwitch = new LoggingLevelSwitch();
|
||||||
_websocketSink = new DebugWebsocketSink();
|
_websocketSink = new DebugWebsocketSink(new CompactJsonFormatter());
|
||||||
|
|
||||||
// Instantiate the root logger
|
// Instantiate the root logger
|
||||||
_logger = new LoggerConfiguration()
|
_logger = new LoggerConfiguration()
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ using WebSocketSharp.Net;
|
|||||||
using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2;
|
using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Org.BouncyCastle.Asn1.X509;
|
using Org.BouncyCastle.Asn1.X509;
|
||||||
|
using Serilog.Formatting;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Serilog.Formatting.Json;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
@@ -47,11 +50,13 @@ namespace PepperDash.Core
|
|||||||
public bool IsRunning { get => _httpsServer?.IsListening ?? false; }
|
public bool IsRunning { get => _httpsServer?.IsListening ?? false; }
|
||||||
|
|
||||||
|
|
||||||
private readonly IFormatProvider _formatProvider;
|
private readonly ITextFormatter _textFormatter;
|
||||||
|
|
||||||
public DebugWebsocketSink()
|
public DebugWebsocketSink(ITextFormatter formatProvider)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_textFormatter = formatProvider ?? new JsonFormatter();
|
||||||
|
|
||||||
if (!File.Exists($"\\user\\{_certificateName}.pfx"))
|
if (!File.Exists($"\\user\\{_certificateName}.pfx"))
|
||||||
CreateCert(null);
|
CreateCert(null);
|
||||||
|
|
||||||
@@ -104,16 +109,11 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (_httpsServer == null || !_httpsServer.IsListening) return;
|
if (_httpsServer == null || !_httpsServer.IsListening) return;
|
||||||
|
|
||||||
var message = logEvent.RenderMessage(_formatProvider);
|
var sw = new StringWriter();
|
||||||
_httpsServer.WebSocketServices.Broadcast(message);
|
_textFormatter.Format(logEvent, sw);
|
||||||
|
|
||||||
|
_httpsServer.WebSocketServices.Broadcast(sw.ToString());
|
||||||
|
|
||||||
foreach(var service in _httpsServer.WebSocketServices.Hosts)
|
|
||||||
{
|
|
||||||
foreach (var session in service.Sessions.Sessions)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartServerAndSetPort(int port)
|
public void StartServerAndSetPort(int port)
|
||||||
@@ -121,10 +121,10 @@ namespace PepperDash.Core
|
|||||||
Debug.Console(0, "Starting Websocket Server on port: {0}", port);
|
Debug.Console(0, "Starting Websocket Server on port: {0}", port);
|
||||||
|
|
||||||
|
|
||||||
Start(port, $"\\user\\{_certificateName}.pfx", _certificatePassword, @"/");
|
Start(port, $"\\user\\{_certificateName}.pfx", _certificatePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start(int port, string certPath = "", string certPassword = "", string rootPath = @"/html")
|
private void Start(int port, string certPath = "", string certPassword = "")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -210,9 +210,9 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
public static LoggerConfiguration DebugWebsocketSink(
|
public static LoggerConfiguration DebugWebsocketSink(
|
||||||
this LoggerSinkConfiguration loggerConfiguration,
|
this LoggerSinkConfiguration loggerConfiguration,
|
||||||
IFormatProvider formatProvider = null)
|
ITextFormatter formatProvider = null)
|
||||||
{
|
{
|
||||||
return loggerConfiguration.Sink(new DebugWebsocketSink());
|
return loggerConfiguration.Sink(new DebugWebsocketSink(formatProvider));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,9 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
|
||||||
<Aliases>Full</Aliases>
|
<Aliases>Full</Aliases>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Serilog" Version="3.0.1" />
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user