Added proper slave mode - additional clients after the first connection. Fixed a few issues. Updated to version 4.8.2.
This commit is contained in:
45
Hermes/Socket/Handlers/LoggingHandler.cs
Normal file
45
Hermes/Socket/Handlers/LoggingHandler.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using CommonSocketLibrary.Abstract;
|
||||
using CommonSocketLibrary.Common;
|
||||
using HermesSocketLibrary.Socket.Data;
|
||||
using Serilog;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Handlers
|
||||
{
|
||||
public class LoggingHandler : IWebSocketHandler
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
public int OperationCode { get; } = 5;
|
||||
|
||||
public LoggingHandler(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Execute<Data>(SocketClient<WebSocketMessage> sender, Data data)
|
||||
{
|
||||
if (data is not LoggingMessage message || message == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
Action<Exception?, string> logging;
|
||||
if (message.Level == HermesLoggingLevel.Trace)
|
||||
logging = _logger.Verbose;
|
||||
else if (message.Level == HermesLoggingLevel.Debug)
|
||||
logging = _logger.Debug;
|
||||
else if (message.Level == HermesLoggingLevel.Info)
|
||||
logging = _logger.Information;
|
||||
else if (message.Level == HermesLoggingLevel.Warn)
|
||||
logging = _logger.Warning;
|
||||
else if (message.Level == HermesLoggingLevel.Error)
|
||||
logging = _logger.Error;
|
||||
else if (message.Level == HermesLoggingLevel.Critical)
|
||||
logging = _logger.Fatal;
|
||||
else {
|
||||
_logger.Warning("Failed to receive a logging level from client.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
logging.Invoke(message.Exception, message.Message);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user