fix: Makes logging more consistent (#1246)

This commit is contained in:
Kamron Batman 2022-11-13 00:36:23 -08:00 committed by GitHub
parent 8e0d01d4be
commit d8cfb6b935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 90 additions and 69 deletions

View file

@ -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:
{