diff --git a/Projects/Server/Configuration/ServerConfiguration.cs b/Projects/Server/Configuration/ServerConfiguration.cs index e3cdaf444..124a6696a 100644 --- a/Projects/Server/Configuration/ServerConfiguration.cs +++ b/Projects/Server/Configuration/ServerConfiguration.cs @@ -228,7 +228,7 @@ public static class ServerConfiguration throw new FileNotFoundException($"Failed to deserialize {m_FilePath}."); } - logger.Information("Reading server configuration done"); + logger.Information("Reading server configuration {Status}", "done"); } else { diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index 5ec76e072..f37eb5269 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -350,7 +350,7 @@ public static class Core _ => "CTRL+C" }; - logger.Information($"Detected {keypress} pressed."); + logger.Information("Detected {Key} pressed.", keypress); e.Cancel = true; Kill(); } @@ -471,27 +471,20 @@ public static class Core ServerConfiguration.Load(); - logger.Information($"Running on {RuntimeInformation.FrameworkDescription}"); + logger.Information("Running on {Framework}", RuntimeInformation.FrameworkDescription); var s = Arguments; if (s.Length > 0) { - logger.Information($"Running with arguments: {s}"); + logger.Information("Running with arguments: {Args}", s); } if (MultiProcessor) { - logger.Information($"Optimizing for {ProcessorCount} processor{(ProcessorCount == 1 ? "" : "s")}"); + logger.Information($"Optimizing for {{ProcessorCount}} processor{(ProcessorCount == 1 ? "" : "s")}", ProcessorCount); } - if (GCSettings.IsServerGC) - { - logger.Information("Server garbage collection mode enabled"); - } - - logger.Information($"High resolution timing ({(Stopwatch.IsHighResolution ? "Supported" : "Unsupported")})"); - var assemblyPath = Path.Join(BaseDirectory, AssembliesConfiguration); // Load UOContent.dll @@ -674,7 +667,7 @@ public static class Core if (errors.Length > 0) { Utility.PushColor(ConsoleColor.Red); - Console.WriteLine($"{type}\n{errors.ToString()}"); + Console.WriteLine($"{type}{Environment.NewLine}{errors.ToString()}"); Utility.PopColor(); } } diff --git a/Projects/Server/Maps/Map.cs b/Projects/Server/Maps/Map.cs index 6804b7bd9..1cda7182d 100644 --- a/Projects/Server/Maps/Map.cs +++ b/Projects/Server/Maps/Map.cs @@ -407,7 +407,11 @@ public sealed class Map : IComparable, ISpanFormattable, ISpanParsable { if (this == Internal && m_Name != "Internal") { - logger.Warning("Internal map name was '{Name}'\n{StackTrace}", m_Name, new StackTrace()); + logger.Warning( + $"Internal map name was '{{Name}}'{Environment.NewLine}{{StackTrace}}", + m_Name, + new StackTrace() + ); m_Name = "Internal"; } @@ -417,7 +421,11 @@ public sealed class Map : IComparable, ISpanFormattable, ISpanParsable { if (this == Internal && value != "Internal") { - logger.Warning("Attempted to set internal map name to '{Value}'\n{StackTrace}", value, new StackTrace()); + logger.Warning( + $"Attempted to set internal map name to '{{Value}}'{Environment.NewLine}{{StackTrace}}", + value, + new StackTrace() + ); value = "Internal"; } diff --git a/Projects/Server/Maps/MapLoader.cs b/Projects/Server/Maps/MapLoader.cs index d90c98af3..2dbf2b17a 100644 --- a/Projects/Server/Maps/MapLoader.cs +++ b/Projects/Server/Maps/MapLoader.cs @@ -80,18 +80,19 @@ public static class MapLoader if (failures.Count > 0) { logger.Warning( - "Map Definitions loaded with failures ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)", + $"Loading map definitions {{Status}} ({{Count}} maps, {{FailureCount}} failures) ({{Duration:F2}} seconds){Environment.NewLine}{{Failures}}", + "failed", count, failures.Count, - stopwatch.Elapsed.TotalSeconds + stopwatch.Elapsed.TotalSeconds, + failures ); - - logger.Warning("Map load failures: {Failure}", failures); } else { logger.Information( - "Map Definitions loaded successfully ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)", + "Loading map definitions {Status} ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)", + "done", count, failures.Count, stopwatch.Elapsed.TotalSeconds diff --git a/Projects/Server/Regions/RegionLoader.cs b/Projects/Server/Regions/RegionLoader.cs index eda07b2c6..177abb17d 100644 --- a/Projects/Server/Regions/RegionLoader.cs +++ b/Projects/Server/Regions/RegionLoader.cs @@ -13,6 +13,7 @@ * along with this program. If not, see . * *************************************************************************/ +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -63,7 +64,8 @@ internal static class RegionLoader if (failures.Count == 0) { logger.Information( - "Regions loaded ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)", + "Loading regions {Status} ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)", + "done", count, failures.Count, stopwatch.Elapsed.TotalSeconds @@ -72,13 +74,13 @@ internal static class RegionLoader else { logger.Warning( - "Failed loading regions ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)", + $"Loading regions {{Status}} ({{Count}} regions, {{FailureCount}} failures) ({{Duration:F2}} seconds){Environment.NewLine}{{Failures}}", + "failed", count, failures.Count, - stopwatch.Elapsed.TotalSeconds + stopwatch.Elapsed.TotalSeconds, + failures ); - - logger.Warning("{Failures}", failures); } } } diff --git a/Projects/Server/TileMatrix/TileMatrixLoader.cs b/Projects/Server/TileMatrix/TileMatrixLoader.cs index 8343c3182..c1da5acfa 100644 --- a/Projects/Server/TileMatrix/TileMatrixLoader.cs +++ b/Projects/Server/TileMatrix/TileMatrixLoader.cs @@ -46,11 +46,16 @@ internal static class TileMatrixLoader if (exception == null) { - logger.Information("Maps loaded ({Duration:F2} seconds)", stopwatch.Elapsed.TotalSeconds); + logger.Information("Loading maps {Status} ({Duration:F2} seconds)", "done", stopwatch.Elapsed.TotalSeconds); } else { - logger.Error(exception, "Loading maps failed ({Duration:F2} seconds)", stopwatch.Elapsed.TotalSeconds); + logger.Error( + exception, + "Loading maps {Status} ({Duration:F2} seconds)", + "failed", + stopwatch.Elapsed.TotalSeconds + ); throw exception; } } diff --git a/Projects/Server/Timer/Timer.DelayCall.cs b/Projects/Server/Timer/Timer.DelayCall.cs index 3aa4837ec..8d8ddf158 100644 --- a/Projects/Server/Timer/Timer.DelayCall.cs +++ b/Projects/Server/Timer/Timer.DelayCall.cs @@ -75,7 +75,7 @@ public partial class Timer t.Start(); #if DEBUG_TIMERS - DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}\n{new StackTrace()}"; + DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}{Environment.NewLine}{new StackTrace()}"; #endif } @@ -102,7 +102,7 @@ public partial class Timer t.Start(); #if DEBUG_TIMERS - DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}\n{new StackTrace()}"; + DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}{Environment.NewLine}{new StackTrace()}"; #endif token = new TimerExecutionToken(t); } @@ -184,7 +184,7 @@ public partial class Timer } #if DEBUG_TIMERS - logger.Warning("Timer pool depleted and timer was allocated.\n{StackTrace}", new StackTrace()); + logger.Warning($"Timer pool depleted and timer was allocated.{Environment.NewLine}{{StackTrace}}", new StackTrace()); #endif return new DelayCallTimer(delay, interval, count, callback); } @@ -198,7 +198,7 @@ public partial class Timer { if (!_allowFinalization) { - logger.Warning("Pooled timer was not returned to the pool.\n{StackTrace}", _stackTraces[GetHashCode()]); + logger.Warning($"Pooled timer was not returned to the pool.{Environment.NewLine}{{StackTrace}}", _stackTraces[GetHashCode()]); } } #endif diff --git a/Projects/Server/Timer/Timer.TimerWheel.cs b/Projects/Server/Timer/Timer.TimerWheel.cs index 868e9782a..a623c5c63 100644 --- a/Projects/Server/Timer/Timer.TimerWheel.cs +++ b/Projects/Server/Timer/Timer.TimerWheel.cs @@ -199,7 +199,7 @@ public partial class Timer if (lastRing && slot > _ringSize) { logger.Error( - "Timer {Timer} has a duration of {Duration}ms, more than max capacity of {MaxDuration}ms.\n{StackTrace}", + $"Timer {{Timer}} has a duration of {{Duration}}ms, more than max capacity of {{MaxDuration}}ms.{Environment.NewLine}{{StackTrace}}", timer.GetType(), originalDelay, _maxDuration, @@ -228,8 +228,8 @@ public partial class Timer public static void DumpInfo(TextWriter tw) { - tw.WriteLine($"Date: {Core.Now.ToLocalTime()}\n"); - tw.WriteLine($"Pool - Count: {_poolCount}; Capacity {_poolCapacity}\n"); + tw.WriteLine($"Date: {Core.Now.ToLocalTime()}{Environment.NewLine}"); + tw.WriteLine($"Pool - Count: {_poolCount}; Capacity {_poolCapacity}{Environment.NewLine}"); var total = 0.0; var hash = new Dictionary(); diff --git a/Projects/Server/Timer/Timer.cs b/Projects/Server/Timer/Timer.cs index f74cf20eb..4b021bc30 100644 --- a/Projects/Server/Timer/Timer.cs +++ b/Projects/Server/Timer/Timer.cs @@ -82,7 +82,7 @@ public partial class Timer if (World.WorldState is WorldState.Saving) { logger.Error( - "Attempted to start timer {Timer} ({HashCode}) while world is {State}\n{StackTrace}", + $"Attempted to start timer {{Timer}} ({{HashCode}}) while world is {{State}}{Environment.NewLine}{{StackTrace}}", GetType(), GetHashCode(), World.WorldState, @@ -94,7 +94,7 @@ public partial class Timer if (Thread.CurrentThread != Core.Thread) { logger.Error( - "Attempted to start timer {Timer} ({HashCode}) from an invalid thread!\n{StackTrace}", + $"Attempted to start timer {{Timer}} ({{HashCode}}) from an invalid thread!{Environment.NewLine}{{StackTrace}}", GetType(), GetHashCode(), new StackTrace() @@ -126,7 +126,7 @@ public partial class Timer if (World.WorldState is WorldState.Saving) { logger.Error( - "Attempted to stop timer {Timer} ({HashCode}) while world is {State}\n{StackTrace}", + $"Attempted to stop timer {{Timer}} ({{HashCode}}) while world is {{State}}{Environment.NewLine}{{StackTrace}}", GetType(), GetHashCode(), World.WorldState, @@ -138,7 +138,7 @@ public partial class Timer if (Thread.CurrentThread != Core.Thread) { logger.Error( - "Attempted to stop timer {Timer} ({HashCode}) from an invalid thread!\n{StackTrace}", + $"Attempted to stop timer {{Timer}} ({{HashCode}}) from an invalid thread!{Environment.NewLine}{{StackTrace}}", GetType(), GetHashCode(), new StackTrace() @@ -231,7 +231,11 @@ public partial class Timer { if (Running) { - logger.Error("{Timer} detached while still running!\n{StackTrace}", this, new StackTrace()); + logger.Error( + $"{{Timer}} detached while still running!{Environment.NewLine}{{StackTrace}}", + this, + new StackTrace() + ); return; } diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index 9f323bef1..8c986d71d 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -302,7 +302,8 @@ public static class World watch.Stop(); - logger.Information("World loaded ({ItemCount} items, {MobileCount} mobiles) ({Duration:F2} seconds)", + logger.Information("Loading world {Status} ({ItemCount} items, {MobileCount} mobiles) ({Duration:F2} seconds)", + "done", Items.Count, Mobiles.Count, watch.Elapsed.TotalSeconds @@ -330,9 +331,9 @@ public static class World private static void AppendSafetyLog(string action, ISerializable entity) { var message = - $"Warning: Attempted to {action} {entity} during world save.{Environment.NewLine}This action could cause inconsistent state.{Environment.NewLine}It is strongly advised that the offending scripts be corrected."; + $"Warning: Attempted to {{Action}} {{Entity}} during world save.{Environment.NewLine}This action could cause inconsistent state.{Environment.NewLine}It is strongly advised that the offending scripts be corrected."; - logger.Information(message); + logger.Information(message, action, entity); try { @@ -418,7 +419,7 @@ public static class World watch.Stop(); - logger.Information("Writing world save snapshot done ({Duration:F2} seconds)", watch.Elapsed.TotalSeconds); + logger.Information("Writing world save snapshot {Status} ({Duration:F2} seconds)", "done", watch.Elapsed.TotalSeconds); } catch (Exception ex) { @@ -427,7 +428,7 @@ public static class World if (exception != null) { - logger.Error(exception, "Writing world save snapshot failed."); + logger.Error(exception, "Writing world save snapshot {Status}.", "failed"); Persistence.TraceException(exception); BroadcastStaff(0x35, true, "Writing world save snapshot failed."); @@ -565,7 +566,7 @@ public static class World if (exception == null) { var duration = watch.Elapsed.TotalSeconds; - logger.Information("World save completed ({Duration:F2} seconds)", duration); + logger.Information("Saving world {Status} ({Duration:F2} seconds)", "done", duration); // Only broadcast if it took at least 150ms if (duration >= 0.15) @@ -575,7 +576,7 @@ public static class World } else { - logger.Error(exception, "World save failed"); + logger.Error(exception, "Saving world {Status}", "failed"); Persistence.TraceException(exception); BroadcastStaff(0x35, true, "World save failed."); @@ -643,7 +644,7 @@ public static class World { default: // Not Running { - throw new Exception($"Added {entity.GetType().Name} before world load.\n"); + throw new Exception($"Added {entity.GetType().Name} before world load."); } case WorldState.Saving: { @@ -671,7 +672,7 @@ public static class World if (existing == entity) { logger.Error( - "Attempted to add '{Entity}' ({Serial}) to World.Items but it already exists in the collection.\n{StackTrace}", + $"Attempted to add '{{Entity}}' ({{Serial}}) to World.Items but it already exists in the collection.{Environment.NewLine}{{StackTrace}}", entity.GetType().FullName, entity.Serial, new StackTrace() @@ -680,7 +681,7 @@ public static class World else { logger.Error( - "Attempted to add '{Entity}' ({Serial}) to World.Items but found '{ExistingEntity}' ({ExistingSerial}).\n{StackTrace}", + $"Attempted to add '{{Entity}}' ({{Serial}}) to World.Items but found '{{ExistingEntity}}' ({{ExistingSerial}}).{Environment.NewLine}{{StackTrace}}", entity.GetType().FullName, entity.Serial, existing.GetType().FullName, @@ -700,7 +701,7 @@ public static class World if (existing == entity) { logger.Error( - "Attempted to add '{Entity}' ({Serial}) to World.Mobiles but it already exists in the collection.\n{StackTrace}", + $"Attempted to add '{{Entity}}' ({{Serial}}) to World.Mobiles but it already exists in the collection.{Environment.NewLine}{{StackTrace}}", entity.GetType().FullName, entity.Serial, new StackTrace() @@ -709,7 +710,7 @@ public static class World else { logger.Error( - "Attempted to add '{{Entity}}' ({{Serial}}) to World.Mobiles but found '{{ExistingEntity}}' ({{ExistingSerial}}).\n{StackTrace}", + $"Attempted to add '{{Entity}}' ({{Serial}}) to World.Mobiles but found '{{ExistingEntity}}' ({{ExistingSerial}}).{Environment.NewLine}{{StackTrace}}", entity.GetType().FullName, entity.Serial, existing.GetType().FullName, @@ -733,7 +734,7 @@ public static class World if (existing == guild) { logger.Error( - "Attempted to add '{Entity}' ({Serial}) to World.Guilds but it already exists in the collection.\n{StackTrace}", + $"Attempted to add '{{Entity}}' ({{Serial}}) to World.Guilds but it already exists in the collection.{Environment.NewLine}{{StackTrace}}", guild.GetType().FullName, guild.Serial, new StackTrace() @@ -742,7 +743,7 @@ public static class World else { logger.Error( - "Attempted to add '{{Entity}}' ({{Serial}}) to World.Guilds but found '{{ExistingEntity}}' ({{ExistingSerial}}).\n{StackTrace}", + $"Attempted to add '{{Entity}}' ({{Serial}}) to World.Guilds but found '{{ExistingEntity}}' ({{ExistingSerial}}).{Environment.NewLine}{{StackTrace}}", guild.GetType().FullName, guild.Serial, existing.GetType().FullName, @@ -759,7 +760,7 @@ public static class World { default: // Not Running { - throw new Exception($"Removed {entity.GetType().Name} before world load.\n"); + throw new Exception($"Removed {entity.GetType().Name} before world load."); } case WorldState.Saving: { diff --git a/Projects/UOContent/Configuration/EmailConfiguration.cs b/Projects/UOContent/Configuration/EmailConfiguration.cs index 0446b889c..6d713d05d 100644 --- a/Projects/UOContent/Configuration/EmailConfiguration.cs +++ b/Projects/UOContent/Configuration/EmailConfiguration.cs @@ -51,17 +51,17 @@ namespace Server.Configurations if (settings == null) { - logger.Error($"Failed reading email configuration from {m_RelPath}"); + logger.Error("Failed reading email configuration from {Path}", m_RelPath); throw new JsonException($"Failed to deserialize {path}."); } - logger.Information($"Email configuration read from {m_RelPath}"); + logger.Information("Email configuration read from {Path}", m_RelPath); } else { settings = new Settings(); JsonConfig.Serialize(path, settings); - logger.Information($"Email configuration saved to {m_RelPath}."); + logger.Information("Email configuration saved to {}.", m_RelPath); } EmailEnabled = settings.enabled; diff --git a/Projects/UOContent/Engines/Spawners/Commands/GenerateSpawnersCommand.cs b/Projects/UOContent/Engines/Spawners/Commands/GenerateSpawnersCommand.cs index 7d86464c6..27c55ea3a 100644 --- a/Projects/UOContent/Engines/Spawners/Commands/GenerateSpawnersCommand.cs +++ b/Projects/UOContent/Engines/Spawners/Commands/GenerateSpawnersCommand.cs @@ -85,7 +85,7 @@ namespace Server.Engines.Spawners { var file = files[i]; from.SendMessage("GenerateSpawners: Generating spawners from {0}...", file.Name); - logger.Information($"{from} is generating spawners from {file.FullName}"); + logger.Information("{User} is generating spawners from {File}", from, file.FullName); NetState.FlushAll(); @@ -213,7 +213,7 @@ namespace Server.Engines.Spawners } #if DEBUG - logger.Error($"{message}\n{ex}"); + logger.Error(ex, message); #endif } } diff --git a/Projects/UOContent/Misc/ClientVerification.cs b/Projects/UOContent/Misc/ClientVerification.cs index 08ff2f7dc..74a31b10a 100644 --- a/Projects/UOContent/Misc/ClientVerification.cs +++ b/Projects/UOContent/Misc/ClientVerification.cs @@ -53,7 +53,9 @@ namespace Server.Misc if (MinRequired != null || MaxRequired != null) { logger.Information( - $"Restricting client version to {GetVersionExpression()}. Action to be taken: {_invalidClientResponse}" + "Restricting client version to {ClientVersion}. Action to be taken: {Action}", + GetVersionExpression(), + _invalidClientResponse ); } } diff --git a/Projects/UOContent/Misc/CrashGuard.cs b/Projects/UOContent/Misc/CrashGuard.cs index a6a695c89..592cc724b 100644 --- a/Projects/UOContent/Misc/CrashGuard.cs +++ b/Projects/UOContent/Misc/CrashGuard.cs @@ -112,11 +112,11 @@ namespace Server.Misc DirectoryCopy(savePath, backupPath); } - logger.Information("Backup done"); + logger.Information("Backup {Status}", "done"); } catch { - logger.Error("Backup failed"); + logger.Error("Backup {Status}", "failed"); } } diff --git a/Projects/UOContent/World Saves/AutoArchive.cs b/Projects/UOContent/World Saves/AutoArchive.cs index e0c3aa60e..aaaf57598 100755 --- a/Projects/UOContent/World Saves/AutoArchive.cs +++ b/Projects/UOContent/World Saves/AutoArchive.cs @@ -99,7 +99,7 @@ namespace Server.Saves var backupPath = Path.Combine(AutomaticBackupPath, Utility.GetTimeStamp()); PathUtility.MoveDirectory(args.OldSavePath, backupPath); - logger.Information($"Created backup at {backupPath}"); + logger.Information("Created backup at {Path}", backupPath); Archive?.Invoke(); } @@ -132,7 +132,7 @@ namespace Server.Saves return false; } - logger.Information($"Restoring latest world save from archive {fileName}"); + logger.Information("Restoring latest world save from archive {File}", fileName); var tempPath = PathUtility.EnsureRandomPath(_tempArchivePath); var successful = fileName.EndsWithOrdinal(".tar.zst") @@ -141,7 +141,7 @@ namespace Server.Saves if (!successful) { - logger.Information($"Failed to extract {fi.Name}"); + logger.Information("Failed to extract {File}", fi.Name); return false; } @@ -149,7 +149,7 @@ namespace Server.Saves { Directory.Delete(savePath, true); var dirInfo = new DirectoryInfo(folder); - logger.Information($"Restoring backup {dirInfo.Name}"); + logger.Information("Restoring backup {Directory}", dirInfo.Name); PathUtility.MoveDirectory(folder, savePath); break; } @@ -188,7 +188,7 @@ namespace Server.Saves if (date < threshold) { - logger.Information($"Pruning old backup {folder}"); + logger.Information("Pruning old backup {Directory}", folder); Directory.Delete(folder, true); } } @@ -213,7 +213,7 @@ namespace Server.Saves } var fi = new FileInfo(archive); - logger.Information($"Pruning {periodLowerStr} archive {fi.Name}"); + logger.Information("Pruning {Period} archive {File}", periodLowerStr, fi.Name); File.Delete(archive); } } @@ -331,7 +331,12 @@ namespace Server.Saves if (archiveCreated) { var elapsed = stopWatch.Elapsed.TotalSeconds; - logger.Information($"Created {archivePeriodStrLower} archive at {archiveFilePath} ({elapsed:F2} seconds)"); + logger.Information( + "Created {Period} archive at {Path} ({Elapsed:F2} seconds)", + archivePeriodStrLower, + archiveFilePath, + elapsed + ); var i = minimum; foreach (var backup in backups)