diff --git a/Core/Callbacks/BundleCallbacks.cs b/Core/Callbacks/BundleCallbacks.cs index bb1ef5e0..b1226380 100644 --- a/Core/Callbacks/BundleCallbacks.cs +++ b/Core/Callbacks/BundleCallbacks.cs @@ -25,7 +25,7 @@ public class BundleCallbacks _httpResponseUtil = httpResponseUtil; // _bundleLoader = bundleLoader; _configServer = configServer; - _httpConfig = configServer.GetConfig(ConfigTypes.HTTP); + _httpConfig = configServer.GetConfig(); } /// diff --git a/Core/Callbacks/ClientLogCallbacks.cs b/Core/Callbacks/ClientLogCallbacks.cs index 906f42b2..e195934b 100644 --- a/Core/Callbacks/ClientLogCallbacks.cs +++ b/Core/Callbacks/ClientLogCallbacks.cs @@ -54,7 +54,7 @@ public class ClientLogCallbacks /// public string ReleaseNotes() { - var data = _configServer.GetConfig(ConfigTypes.CORE).Release; + var data = _configServer.GetConfig().Release; data.BetaDisclaimerText = "BetaDisclaimerText"; data.BetaDisclaimerAcceptText = "BetaDisclaimerAcceptText"; data.ServerModsLoadedText = "ServerModsLoadedText"; @@ -97,7 +97,7 @@ public class ClientLogCallbacks /// public string BsgLogging() { - var data = _configServer.GetConfig(ConfigTypes.CORE).BsgLogging; + var data = _configServer.GetConfig().BsgLogging; return _httpResponseUtil.NoBody(data); } } diff --git a/Core/Callbacks/HideoutCallbacks.cs b/Core/Callbacks/HideoutCallbacks.cs index c5f72a45..81b69248 100644 --- a/Core/Callbacks/HideoutCallbacks.cs +++ b/Core/Callbacks/HideoutCallbacks.cs @@ -25,7 +25,7 @@ public class HideoutCallbacks : OnUpdate { _hideoutController = hideoutController; _configServer = configServer; - _hideoutConfig = configServer.GetConfig(ConfigTypes.HIDEOUT); + _hideoutConfig = configServer.GetConfig(); } /// diff --git a/Core/Callbacks/InsuranceCallbacks.cs b/Core/Callbacks/InsuranceCallbacks.cs index c1bb90e5..99ef1c0e 100644 --- a/Core/Callbacks/InsuranceCallbacks.cs +++ b/Core/Callbacks/InsuranceCallbacks.cs @@ -36,7 +36,7 @@ public class InsuranceCallbacks : OnUpdate _insuranceService = insuranceService; _httpResponseUtil = httpResponseUtil; _configServer = configServer; - _insuranceConfig = configServer.GetConfig(ConfigTypes.INSURANCE); + _insuranceConfig = configServer.GetConfig(); } /// diff --git a/Core/Callbacks/RagfairCallbacks.cs b/Core/Callbacks/RagfairCallbacks.cs index e42c0f7d..641c7287 100644 --- a/Core/Callbacks/RagfairCallbacks.cs +++ b/Core/Callbacks/RagfairCallbacks.cs @@ -39,7 +39,7 @@ public class RagfairCallbacks : OnLoad, OnUpdate _ragfairController = ragfairController; _ragfairTaxService = ragfairTaxService; _configServer = configServer; - _ragfairConfig = _configServer.GetConfig(ConfigTypes.RAGFAIR); + _ragfairConfig = _configServer.GetConfig(); } public async Task OnLoad() diff --git a/Core/Callbacks/SaveCallbacks.cs b/Core/Callbacks/SaveCallbacks.cs index 103ac844..5f8bd346 100644 --- a/Core/Callbacks/SaveCallbacks.cs +++ b/Core/Callbacks/SaveCallbacks.cs @@ -22,7 +22,7 @@ public class SaveCallbacks : OnLoad, OnUpdate ) { _saveServer = saveServer; - _coreConfig = configServer.GetConfig(ConfigTypes.CORE); + _coreConfig = configServer.GetConfig(); _backupService = backupService; } diff --git a/Core/Callbacks/TraderCallbacks.cs b/Core/Callbacks/TraderCallbacks.cs index 11f443db..cf63b8d8 100644 --- a/Core/Callbacks/TraderCallbacks.cs +++ b/Core/Callbacks/TraderCallbacks.cs @@ -94,7 +94,7 @@ public class TraderCallbacks : OnLoad, OnUpdate /// public string GetModdedTraderData(string url, EmptyRequestData info, string sessionID) { - var traderConfig = _configServer.GetConfig(ConfigTypes.TRADER); + var traderConfig = _configServer.GetConfig(); return _httpResponseUtil.NoBody(traderConfig.ModdedTraders); } } diff --git a/Core/Controllers/BotController.cs b/Core/Controllers/BotController.cs index f6435cc4..e2931a3d 100644 --- a/Core/Controllers/BotController.cs +++ b/Core/Controllers/BotController.cs @@ -76,8 +76,8 @@ public class BotController _applicationContext = applicationContext; _randomUtil = randomUtil; _cloner = cloner; - _botConfig = _configServer.GetConfig(ConfigTypes.BOT); - _pmcConfig = _configServer.GetConfig(ConfigTypes.PMC); + _botConfig = _configServer.GetConfig(); + _pmcConfig = _configServer.GetConfig(); } public int GetBotPresetGenerationLimit(string type) diff --git a/Core/Controllers/GameController.cs b/Core/Controllers/GameController.cs index 2b156f33..6ebb43de 100644 --- a/Core/Controllers/GameController.cs +++ b/Core/Controllers/GameController.cs @@ -96,11 +96,11 @@ public class GameController _applicationContext = applicationContext; _cloner = cloner; - _coreConfig = configServer.GetConfig(ConfigTypes.CORE); - _httpConfig = configServer.GetConfig(ConfigTypes.HTTP); - _ragfairConfig = configServer.GetConfig(ConfigTypes.RAGFAIR); - _hideoutConfig = configServer.GetConfig(ConfigTypes.HIDEOUT); - _botConfig = configServer.GetConfig(ConfigTypes.BOT); + _coreConfig = configServer.GetConfig(); + _httpConfig = configServer.GetConfig(); + _ragfairConfig = configServer.GetConfig(); + _hideoutConfig = configServer.GetConfig(); + _botConfig = configServer.GetConfig(); } /// diff --git a/Core/Controllers/InRaidController.cs b/Core/Controllers/InRaidController.cs index 758679b9..be61b5f1 100644 --- a/Core/Controllers/InRaidController.cs +++ b/Core/Controllers/InRaidController.cs @@ -39,8 +39,8 @@ public class InRaidController _localisationService = localisationService; _applicationContext = applicationContext; _configServer = configServer; - _inRaidConfig = configServer.GetConfig(ConfigTypes.IN_RAID); - _botConfig = configServer.GetConfig(ConfigTypes.BOT); + _inRaidConfig = configServer.GetConfig(); + _botConfig = configServer.GetConfig(); } /// diff --git a/Core/Controllers/LauncherController.cs b/Core/Controllers/LauncherController.cs index 1f1af4f7..bc1f997d 100644 --- a/Core/Controllers/LauncherController.cs +++ b/Core/Controllers/LauncherController.cs @@ -54,7 +54,7 @@ public class LauncherController _profileHelper = profileHelper; _databaseService = databaseService; _localisationService = localisationService; - _coreConfig = configServer.GetConfig(ConfigTypes.CORE); + _coreConfig = configServer.GetConfig(); } public ConnectResponse Connect() diff --git a/Core/Controllers/TradeController.cs b/Core/Controllers/TradeController.cs index 030add0c..5ff11081 100644 --- a/Core/Controllers/TradeController.cs +++ b/Core/Controllers/TradeController.cs @@ -71,8 +71,8 @@ public class TradeController _ragfairPriceService = ragfairPriceService; _configServer = configServer; - _ragfairConfig = _configServer.GetConfig(ConfigTypes.RAGFAIR); - _traderConfig = _configServer.GetConfig(ConfigTypes.TRADER); + _ragfairConfig = _configServer.GetConfig(); + _traderConfig = _configServer.GetConfig(); } /// diff --git a/Core/Controllers/TraderController.cs b/Core/Controllers/TraderController.cs index e27aa89b..a11a501a 100644 --- a/Core/Controllers/TraderController.cs +++ b/Core/Controllers/TraderController.cs @@ -67,7 +67,7 @@ public class TraderController _configServer = configServer; _cloner = cloner; - _traderConfig = configServer.GetConfig(ConfigTypes.TRADER); + _traderConfig = configServer.GetConfig(); } /// diff --git a/Core/Controllers/WeatherController.cs b/Core/Controllers/WeatherController.cs index 8cc014d3..a670419c 100644 --- a/Core/Controllers/WeatherController.cs +++ b/Core/Controllers/WeatherController.cs @@ -39,7 +39,7 @@ public class WeatherController _weatherHelper = weatherHelper; _configServer = configServer; - _weatherConfig = _configServer.GetConfig(ConfigTypes.WEATHER); + _weatherConfig = _configServer.GetConfig(); } /// diff --git a/Core/Generators/PlayerScavGenerator.cs b/Core/Generators/PlayerScavGenerator.cs index 78d927ff..84f6fc96 100644 --- a/Core/Generators/PlayerScavGenerator.cs +++ b/Core/Generators/PlayerScavGenerator.cs @@ -71,7 +71,7 @@ public class PlayerScavGenerator _cloner = cloner; _timeUtil = timeUtil; - _playerScavConfig = configServer.GetConfig(ConfigTypes.PLAYERSCAV); + _playerScavConfig = configServer.GetConfig(); } /// diff --git a/Core/Generators/WeatherGenerator.cs b/Core/Generators/WeatherGenerator.cs index bd254ace..454ea05f 100644 --- a/Core/Generators/WeatherGenerator.cs +++ b/Core/Generators/WeatherGenerator.cs @@ -30,7 +30,7 @@ public class WeatherGenerator _weatherHelper = weatherHelper; _configServer = configServer; - _weatherConfig = _configServer.GetConfig(ConfigTypes.WEATHER); + _weatherConfig = _configServer.GetConfig(); } /** diff --git a/Core/Helpers/HttpServerHelper.cs b/Core/Helpers/HttpServerHelper.cs index 55e573a1..b49ec0ee 100644 --- a/Core/Helpers/HttpServerHelper.cs +++ b/Core/Helpers/HttpServerHelper.cs @@ -26,7 +26,7 @@ public class HttpServerHelper public HttpServerHelper(ConfigServer configServer) { - _httpConfig = configServer.GetConfig(ConfigTypes.HTTP); + _httpConfig = configServer.GetConfig(); } public string GetMimeText(string key) diff --git a/Core/Helpers/PaymentHelper.cs b/Core/Helpers/PaymentHelper.cs index 8b812afc..54fc6517 100644 --- a/Core/Helpers/PaymentHelper.cs +++ b/Core/Helpers/PaymentHelper.cs @@ -16,7 +16,7 @@ public class PaymentHelper { _configServer = configServer; - _inventoryConfig = _configServer.GetConfig(ConfigTypes.INVENTORY); + _inventoryConfig = _configServer.GetConfig(); } /// diff --git a/Core/Helpers/ProfileHelper.cs b/Core/Helpers/ProfileHelper.cs index 8de4d0dd..0032b4b7 100644 --- a/Core/Helpers/ProfileHelper.cs +++ b/Core/Helpers/ProfileHelper.cs @@ -46,7 +46,7 @@ public class ProfileHelper _timeUtil = timeUtil; _localisationService = localisationService; _hashUtil = hashUtil; - _inventoryConfig = configServer.GetConfig(ConfigTypes.INVENTORY); + _inventoryConfig = configServer.GetConfig(); } /// diff --git a/Core/Helpers/QuestHelper.cs b/Core/Helpers/QuestHelper.cs index 1ffd5b89..cc727266 100644 --- a/Core/Helpers/QuestHelper.cs +++ b/Core/Helpers/QuestHelper.cs @@ -47,7 +47,7 @@ public class QuestHelper _localeService = localeService; _cloner = Cloner; - _questConfig = configServer.GetConfig(ConfigTypes.QUEST); + _questConfig = configServer.GetConfig(); } /// diff --git a/Core/Helpers/QuestRewardHelper.cs b/Core/Helpers/QuestRewardHelper.cs index cff6ef44..5f30e1e5 100644 --- a/Core/Helpers/QuestRewardHelper.cs +++ b/Core/Helpers/QuestRewardHelper.cs @@ -59,7 +59,7 @@ public class QuestRewardHelper _localisationService = localisationService; _cloner = cloner; - _questConfig = configServer.GetConfig(ConfigTypes.QUEST); + _questConfig = configServer.GetConfig(); } /** diff --git a/Core/Helpers/TraderHelper.cs b/Core/Helpers/TraderHelper.cs index b7030489..a5bded75 100644 --- a/Core/Helpers/TraderHelper.cs +++ b/Core/Helpers/TraderHelper.cs @@ -44,7 +44,7 @@ public class TraderHelper _profileHelper = profileHelper; _databaseService = databaseService; - _traderConfig = _configServer.GetConfig(ConfigTypes.TRADER); + _traderConfig = _configServer.GetConfig(); } /// diff --git a/Core/Helpers/WeatherHelper.cs b/Core/Helpers/WeatherHelper.cs index 9912a883..d8b1f934 100644 --- a/Core/Helpers/WeatherHelper.cs +++ b/Core/Helpers/WeatherHelper.cs @@ -27,7 +27,7 @@ public class WeatherHelper _timeUtil = timeUtil; _configServer = configServer; - _weatherConfig = _configServer.GetConfig(ConfigTypes.WEATHER); + _weatherConfig = _configServer.GetConfig(); } /// diff --git a/Core/Servers/ConfigServer.cs b/Core/Servers/ConfigServer.cs index c7c6097e..7275e1e6 100644 --- a/Core/Servers/ConfigServer.cs +++ b/Core/Servers/ConfigServer.cs @@ -1,7 +1,4 @@ -using System.Runtime.InteropServices.JavaScript; -using System.Text.Json; -using System.Text.Json.Serialization; -using Core.Annotations; +using Core.Annotations; using Core.Models.Enums; using Core.Models.Spt.Config; using Core.Utils; @@ -30,11 +27,20 @@ public class ConfigServer Initialize(); } - public T GetConfig(ConfigTypes configType) where T : BaseConfig + public T GetConfig() where T : BaseConfig { - if (!configs.ContainsKey(configType.GetValue())) throw new Exception($"Config: {configType} is undefined. Ensure you have not broken it via editing"); + var configKey = GetConfigKey(typeof(T)); + if (!configs.ContainsKey(configKey.GetValue())) throw new Exception($"Config: {configKey} is undefined. Ensure you have not broken it via editing"); - return configs[configType.GetValue()] as T; + return configs[configKey.GetValue()] as T; + } + + private ConfigTypes GetConfigKey(Type type) + { + var configEnumerable = Enum.GetValues().Where(e => e.GetConfigType() == type); + if (!configEnumerable.Any()) + throw new Exception($"Config of type {type.Name} is not mapped to any ConfigTypes"); + return configEnumerable.First(); } public T GetConfigByString(string configType) where T : BaseConfig diff --git a/Core/Servers/HttpServer.cs b/Core/Servers/HttpServer.cs index d21ebc10..b9df0aa8 100644 --- a/Core/Servers/HttpServer.cs +++ b/Core/Servers/HttpServer.cs @@ -39,7 +39,7 @@ public class HttpServer _webSocketServer = webSocketServer; _httpListeners = httpListeners; - httpConfig = _configServer.GetConfig(ConfigTypes.HTTP); + httpConfig = _configServer.GetConfig(); } public void Load(WebApplicationBuilder builder) diff --git a/Core/Servers/SaveServer.cs b/Core/Servers/SaveServer.cs index 839e4b07..432325eb 100644 --- a/Core/Servers/SaveServer.cs +++ b/Core/Servers/SaveServer.cs @@ -235,7 +235,7 @@ public class SaveServer } var start = Stopwatch.StartNew(); - var jsonProfile = _jsonUtil.Serialize(profiles[sessionID], !_configServer.GetConfig(ConfigTypes.CORE).Features.CompressProfile); + var jsonProfile = _jsonUtil.Serialize(profiles[sessionID], !_configServer.GetConfig().Features.CompressProfile); var fmd5 = _hashUtil.GenerateMd5ForData(jsonProfile); if (!saveMd5.TryGetValue(sessionID, out var currentMd5) || currentMd5 != fmd5) { diff --git a/Core/Services/GiftService.cs b/Core/Services/GiftService.cs index c5c7b952..337a8c5a 100644 --- a/Core/Services/GiftService.cs +++ b/Core/Services/GiftService.cs @@ -24,7 +24,7 @@ public class GiftService _configServer = configServer; _profileHelper = profileHelper; - _giftConfig = _configServer.GetConfig(ConfigTypes.GIFTS); + _giftConfig = _configServer.GetConfig(); } /** diff --git a/Core/Services/LocaleService.cs b/Core/Services/LocaleService.cs index d325c60a..37d0e770 100644 --- a/Core/Services/LocaleService.cs +++ b/Core/Services/LocaleService.cs @@ -20,7 +20,7 @@ public class LocaleService _logger = logger; _databaseServer = databaseServer; _configServer = configServer; - _localeConfig = configServer.GetConfig(ConfigTypes.LOCALE); + _localeConfig = configServer.GetConfig(); } /** diff --git a/Core/Services/ProfileFixerService.cs b/Core/Services/ProfileFixerService.cs index 90cde9a5..570897be 100644 --- a/Core/Services/ProfileFixerService.cs +++ b/Core/Services/ProfileFixerService.cs @@ -53,7 +53,7 @@ public class ProfileFixerService _configServer = configServer; _inventoryHelper = inventoryHelper; - _coreConfig = _configServer.GetConfig(ConfigTypes.CORE); + _coreConfig = _configServer.GetConfig(); } /// diff --git a/Core/Services/RaidWeatherService.cs b/Core/Services/RaidWeatherService.cs index 6ad3e87f..a1813cee 100644 --- a/Core/Services/RaidWeatherService.cs +++ b/Core/Services/RaidWeatherService.cs @@ -42,7 +42,7 @@ public class RaidWeatherService _weightedRandomHelper = weightedRandomHelper; _configServer = configServer; - _weatherConfig = _configServer.GetConfig(ConfigTypes.WEATHER); + _weatherConfig = _configServer.GetConfig(); } /// diff --git a/Core/Services/TraderPurchasePersisterService.cs b/Core/Services/TraderPurchasePersisterService.cs index 0adca3d0..f05ad9ce 100644 --- a/Core/Services/TraderPurchasePersisterService.cs +++ b/Core/Services/TraderPurchasePersisterService.cs @@ -36,7 +36,7 @@ public class TraderPurchasePersisterService _localisationService = localisationService; _configServer = configServer; - _traderConfig = _configServer.GetConfig(ConfigTypes.TRADER); + _traderConfig = _configServer.GetConfig(); } /** diff --git a/Core/Utils/App.cs b/Core/Utils/App.cs index 5ef4b347..c278c5ea 100644 --- a/Core/Utils/App.cs +++ b/Core/Utils/App.cs @@ -47,7 +47,7 @@ public class App _onLoad = onLoadComponents; _onUpdate = onUpdateComponents; - _coreConfig = configServer.GetConfig(ConfigTypes.CORE); + _coreConfig = configServer.GetConfig(); } public async Task Run() diff --git a/Core/Utils/DatabaseImporter.cs b/Core/Utils/DatabaseImporter.cs index 76f3e2ec..4dbd7a64 100644 --- a/Core/Utils/DatabaseImporter.cs +++ b/Core/Utils/DatabaseImporter.cs @@ -54,7 +54,7 @@ public class DatabaseImporter : OnLoad _configServer = configServer; _fileUtil = fileUtil; _imageRouter = imageRouter; - httpConfig = _configServer.GetConfig(ConfigTypes.HTTP); + httpConfig = _configServer.GetConfig(); } /** diff --git a/Core/Utils/ImporterUtil.cs b/Core/Utils/ImporterUtil.cs index 953253be..023591aa 100644 --- a/Core/Utils/ImporterUtil.cs +++ b/Core/Utils/ImporterUtil.cs @@ -3,6 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using Core.Annotations; using Core.Utils.Json.Converters; +using ILogger = Core.Models.Utils.ILogger; namespace Core.Utils; @@ -11,11 +12,13 @@ public class ImporterUtil { private readonly FileUtil _fileUtil; private readonly JsonUtil _jsonUtil; + private readonly Models.Utils.ILogger _logger; private readonly HashSet filesToIgnore = ["bearsuits.json", "usecsuits.json", "archivedquests.json"]; - public ImporterUtil(FileUtil fileUtil, JsonUtil jsonUtil) + public ImporterUtil(ILogger logger, FileUtil fileUtil, JsonUtil jsonUtil) { + _logger = logger; _fileUtil = fileUtil; _jsonUtil = jsonUtil; } @@ -96,8 +99,16 @@ public class ImporterUtil return Task.WhenAll(tasks).ContinueWith((t) => { if (t.IsCanceled || t.IsFaulted) - tasks.Where(t => t.IsFaulted || t.IsCanceled).ToList().ForEach(t => Console.WriteLine(t.Exception)); - }).ContinueWith(_ => result); + { + var exceptionList = tasks.Where(t => t.IsFaulted || t.IsCanceled).Select(t => t.Exception!).ToList(); + throw new Exception("Error processing one or more DatabaseFiles", new AggregateException(exceptionList)); + } + }).ContinueWith(t => + { + if (t.IsFaulted || t.IsCanceled) + throw t.Exception!; + return result; + }); } public MethodInfo GetSetMethod(string propertyName, Type type, out Type propertyType, out bool isDictionary) diff --git a/Core/Utils/Watermark.cs b/Core/Utils/Watermark.cs index 2622a1b1..14d4f52a 100644 --- a/Core/Utils/Watermark.cs +++ b/Core/Utils/Watermark.cs @@ -65,7 +65,7 @@ public class Watermark { _configServer = configServer; _localisationService = localisationService; _watermarkLocale = watermarkLocale; - sptConfig = _configServer.GetConfig(ConfigTypes.CORE); + sptConfig = _configServer.GetConfig(); } public virtual void Initialize() diff --git a/Server/Logger/FileFormatter.cs b/Server/Logger/FileFormatter.cs index d7872231..7c079c57 100644 --- a/Server/Logger/FileFormatter.cs +++ b/Server/Logger/FileFormatter.cs @@ -6,7 +6,7 @@ public class FileFormatter : AbstractFormatter { protected override string ProcessText(string message) { - foreach (Match match in Regex.Matches(message, @"\x1b\[((\d.+?)?\d)m")) + foreach (Match match in Regex.Matches(message, @"\x1b\[[0-9]{1,2}(;[0-1]{1,2}){0,1}m")) { message = message.Replace(match.Value, ""); } diff --git a/Server/Program.cs b/Server/Program.cs index db0e6279..d3f74c21 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Security.Cryptography; using Core.Annotations; using Core.Context; using Core.Models.Enums; @@ -7,8 +6,12 @@ using Core.Models.External; using Core.Models.Spt.Config; using Core.Servers; using Core.Utils; +using Microsoft.Extensions.Logging.Configuration; using Serilog; using Serilog.Events; +using Serilog.Exceptions; +using Serilog.Extensions.Logging; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Server; @@ -22,10 +25,11 @@ public static class Program builder.Configuration.AddJsonFile("appsettings.json", true, true); - CreateAndRegisterLogger(builder); + CreateAndRegisterLogger(builder, out var registeredLogger); RegisterSptComponents(builder.Services); RegisterModOverrideComponents(builder.Services, assemblies); + ILogger logger = new SerilogLoggerProvider(registeredLogger).CreateLogger("Server"); try { var serviceProvider = builder.Services.BuildServiceProvider(); @@ -49,23 +53,27 @@ public static class Program var app = serviceProvider.GetService(); app.Run().Wait(); - var httpConfig = serviceProvider.GetService().GetConfig(ConfigTypes.HTTP); + var httpConfig = serviceProvider.GetService().GetConfig(); // When we application gets started by the HttpServer it will add into the AppContext the WebApplication // object, which we can use here to start the webapp. (appContext.GetLatestValue(ContextVariableType.WEB_APPLICATION).Value as WebApplication).Run($"http://{httpConfig.Ip}:{httpConfig.Port}"); } catch (Exception ex) { - Console.WriteLine(ex.ToString()); + logger.LogCritical(ex, "Critical exception, stopping server..."); + // throw ex; } } - private static void CreateAndRegisterLogger(WebApplicationBuilder builder) + private static void CreateAndRegisterLogger(WebApplicationBuilder builder, out Serilog.Core.Logger logger) { builder.Logging.ClearProviders(); - var logger = new LoggerConfiguration() + logger = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Warning) + .Enrich.FromLogContext() + .Enrich.WithThreadId() + .Enrich.WithExceptionDetails() .CreateLogger(); builder.Logging.AddSerilog(logger); } diff --git a/Server/Server.csproj b/Server/Server.csproj index c73311b6..56863876 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -19,6 +19,9 @@ + + + diff --git a/Server/appsettings.json b/Server/appsettings.json index c6b43de4..c1936e7a 100644 --- a/Server/appsettings.json +++ b/Server/appsettings.json @@ -40,6 +40,10 @@ "expression": "StartsWith(SourceContext, 'TADAADA')" } } + ], + "Enrich": [ + "FromLogContext", + "WithExceptionDetails" ] } }