mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 07:13:58 -05:00
refactor logging in pretty big overhaul
This commit is contained in:
@ -3,12 +3,14 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using SharedLibraryCore.Helpers;
|
||||
using SharedLibraryCore.Dtos;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace SharedLibraryCore
|
||||
{
|
||||
@ -28,14 +30,15 @@ namespace SharedLibraryCore
|
||||
T7 = 8
|
||||
}
|
||||
|
||||
public Server(ServerConfiguration config, IManager mgr, IRConConnectionFactory rconConnectionFactory, IGameLogReaderFactory gameLogReaderFactory)
|
||||
public Server(ILogger<Server> logger, SharedLibraryCore.Interfaces.ILogger deprecatedLogger,
|
||||
ServerConfiguration config, IManager mgr, IRConConnectionFactory rconConnectionFactory,
|
||||
IGameLogReaderFactory gameLogReaderFactory)
|
||||
{
|
||||
Password = config.Password;
|
||||
IP = config.IPAddress;
|
||||
Port = config.Port;
|
||||
Manager = mgr;
|
||||
Logger = Manager.GetLogger(this.EndPoint);
|
||||
Logger.WriteInfo(this.ToString());
|
||||
Logger = deprecatedLogger;
|
||||
ServerConfig = config;
|
||||
RemoteConnection = rconConnectionFactory.CreateConnection(IP, Port, Password);
|
||||
EventProcessing = new SemaphoreSlim(1, 1);
|
||||
@ -47,6 +50,7 @@ namespace SharedLibraryCore
|
||||
CustomSayEnabled = Manager.GetApplicationSettings().Configuration().EnableCustomSayName;
|
||||
CustomSayName = Manager.GetApplicationSettings().Configuration().CustomSayName;
|
||||
this.gameLogReaderFactory = gameLogReaderFactory;
|
||||
ServerLogger = logger;
|
||||
InitializeTokens();
|
||||
InitializeAutoMessages();
|
||||
}
|
||||
@ -123,9 +127,7 @@ namespace SharedLibraryCore
|
||||
public GameEvent Broadcast(string message, EFClient sender = null)
|
||||
{
|
||||
string formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "", $"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FixIW4ForwardSlash()}");
|
||||
#if DEBUG == true
|
||||
Logger.WriteVerbose(message.StripColors());
|
||||
#endif
|
||||
ServerLogger.LogDebug("All->" + message.StripColors());
|
||||
|
||||
var e = new GameEvent()
|
||||
{
|
||||
@ -146,18 +148,27 @@ namespace SharedLibraryCore
|
||||
/// <param name="target">EFClient to send message to</param>
|
||||
protected async Task Tell(string message, EFClient target)
|
||||
{
|
||||
#if !DEBUG
|
||||
string formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Tell, target.ClientNumber, $"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FixIW4ForwardSlash()}");
|
||||
if (target.ClientNumber > -1 && message.Length > 0 && target.Level != EFClient.Permission.Console)
|
||||
await this.ExecuteCommandAsync(formattedMessage);
|
||||
#else
|
||||
Logger.WriteVerbose($"{target.ClientNumber}->{message.StripColors()}");
|
||||
await Task.CompletedTask;
|
||||
#endif
|
||||
if (!Utilities.IsDevelopment)
|
||||
{
|
||||
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Tell,
|
||||
target.ClientNumber,
|
||||
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FixIW4ForwardSlash()}");
|
||||
if (target.ClientNumber > -1 && message.Length > 0 && target.Level != EFClient.Permission.Console)
|
||||
await this.ExecuteCommandAsync(formattedMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerLogger.LogDebug("Tell[{clientNumber}]->{message}", target.ClientNumber, message.StripColors());
|
||||
}
|
||||
|
||||
|
||||
if (target.Level == EFClient.Permission.Console)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
using (LogContext.PushProperty("Server", ToString()))
|
||||
{
|
||||
ServerLogger.LogInformation("Command output received: {message}", message);
|
||||
}
|
||||
Console.WriteLine(message.StripColors());
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
@ -280,7 +291,8 @@ namespace SharedLibraryCore
|
||||
|
||||
// Objects
|
||||
public IManager Manager { get; protected set; }
|
||||
public ILogger Logger { get; private set; }
|
||||
[Obsolete]
|
||||
public SharedLibraryCore.Interfaces.ILogger Logger { get; private set; }
|
||||
public ServerConfiguration ServerConfig { get; private set; }
|
||||
public List<Map> Maps { get; protected set; } = new List<Map>();
|
||||
public List<Report> Reports { get; set; }
|
||||
@ -319,6 +331,7 @@ namespace SharedLibraryCore
|
||||
public string IP { get; protected set; }
|
||||
public string Version { get; protected set; }
|
||||
public bool IsInitialized { get; set; }
|
||||
protected readonly ILogger ServerLogger;
|
||||
|
||||
public int Port { get; private set; }
|
||||
protected string FSGame;
|
||||
|
Reference in New Issue
Block a user