From f755afcb79443fe8d1b2a480fab14110c7753141 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 18 Jan 2025 18:35:27 +0000 Subject: [PATCH] Improved logging --- Core/Models/Utils/ISptLogger.cs | 7 +++---- Core/Routers/ItemEventRouter.cs | 10 +++++----- Server/Logger/WebApplicationLogger.cs | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Core/Models/Utils/ISptLogger.cs b/Core/Models/Utils/ISptLogger.cs index c427755d..d748b481 100644 --- a/Core/Models/Utils/ISptLogger.cs +++ b/Core/Models/Utils/ISptLogger.cs @@ -5,15 +5,14 @@ namespace Core.Models.Utils; public interface ISptLogger { - // TODO: Removing these 4 methods for now, revisit in the future - // void WriteToLogFile(string data); + // TODO: Removing these methods for now, revisit in the future // void Log(string data, LogTextColor? color, string? backgroundColor = null); - void LogWithColor(string data, Exception? ex = null, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null); + void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null, Exception? ex = null); void Success(string data, Exception? ex = null); void Error(string data, Exception? ex = null); void Warning(string data, Exception? ex = null); void Info(string data, Exception? ex = null); void Debug(string data, Exception? ex = null); void Critical(string data, Exception? ex = null); - void WriteToLogFile(object body); + void WriteToLogFile(string body); } diff --git a/Core/Routers/ItemEventRouter.cs b/Core/Routers/ItemEventRouter.cs index 38b79796..61d12ffe 100644 --- a/Core/Routers/ItemEventRouter.cs +++ b/Core/Routers/ItemEventRouter.cs @@ -1,14 +1,11 @@ using Core.Annotations; using Core.DI; using Core.Helpers; -using Core.Models.Eft.HttpResponse; using Core.Models.Eft.ItemEvent; -using Core.Models.Enums; using Core.Models.Utils; using Core.Services; using Core.Utils; using Core.Utils.Cloners; -using Microsoft.AspNetCore.Http; namespace Core.Routers { @@ -16,7 +13,8 @@ namespace Core.Routers public class ItemEventRouter { protected ISptLogger _logger; - private readonly HttpResponseUtil _httpResponseUtil; + protected HttpResponseUtil _httpResponseUtil; + protected JsonUtil _jsonUtil; protected ProfileHelper _profileHelper; protected LocalisationService _localisationService; protected EventOutputHolder _eventOutputHolder; @@ -26,6 +24,7 @@ namespace Core.Routers public ItemEventRouter( ISptLogger logger, HttpResponseUtil httpResponseUtil, + JsonUtil jsonUtil, ProfileHelper profileHelper, LocalisationService localisationService, EventOutputHolder eventOutputHolder, @@ -35,6 +34,7 @@ namespace Core.Routers { _logger = logger; _httpResponseUtil = httpResponseUtil; + _jsonUtil = jsonUtil; _profileHelper = profileHelper; _localisationService = localisationService; _eventOutputHolder = eventOutputHolder; @@ -53,7 +53,7 @@ namespace Core.Routers if (eventRouter is null) { _logger.Error(_localisationService.GetText("event-unhandled_event", body.Action)); - _logger.WriteToLogFile(body); + _logger.WriteToLogFile(_jsonUtil.Serialize(info.Data)); continue; } diff --git a/Server/Logger/WebApplicationLogger.cs b/Server/Logger/WebApplicationLogger.cs index 66142c61..455d16ca 100644 --- a/Server/Logger/WebApplicationLogger.cs +++ b/Server/Logger/WebApplicationLogger.cs @@ -17,9 +17,9 @@ public class SptWebApplicationLogger : ISptLogger public void LogWithColor( string data, - Exception? ex = null, LogTextColor? textColor = null, - LogBackgroundColor? backgroundColor = null + LogBackgroundColor? backgroundColor = null, + Exception? ex = null ) { if (textColor != null || backgroundColor != null) @@ -83,7 +83,7 @@ public class SptWebApplicationLogger : ISptLogger throw new NotImplementedException(); } - public void WriteToLogFile(object data) + public void WriteToLogFile(string data) { //TODO - implement + turn object into json _logger.LogError("NOT IMPLEMENTED - WriteToLogFile");