fix: Fixes structured logging (#1043)

- [X] Fixes various bugs in logging.
This commit is contained in:
Kamron Batman 2022-06-05 01:00:22 -07:00 • committed by GitHub
parent 78bb4f4bb2
commit 6e69d25e33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 96 additions and 102 deletions

View file

@ -22,14 +22,14 @@ namespace Server
if (Firewall.IsBlocked(ip))
{
logger.Information("Client: {0}: Firewall blocked connection attempt.", ip);
logger.Information("Client: {IP}: Firewall blocked connection attempt.", ip);
e.AllowConnection = false;
return;
}
if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip))
{
logger.Warning("Client: {0}: Past IP limit threshold", ip);
logger.Warning("Client: {IP}: Past IP limit threshold", ip);
using (var op = new StreamWriter("ipLimits.log", true))
{

View file

@ -255,7 +255,7 @@ namespace Server.Misc
}
else
{
state.LogInfo("Deleting character {0} (0x{1:X})", index, m.Serial.Value);
state.LogInfo($"Deleting character {index} (0x{m.Serial.Value:X})");
acct.Comments.Add(new AccountComment("System", $"Character #{index + 1} {m} deleted by {state}"));
@ -314,16 +314,16 @@ namespace Server.Misc
if (!CanCreate(state.Address))
{
logger.Information(
"Login: {0}: Account '{1}' not created, ip already has {2} account{3}.",
$"Login: {{NetState}} Account '{{Username}}' not created, ip already has {{AccountCount}} account{(MaxAccountsPerIP == 1 ? "" : "s")}.",
state,
un,
MaxAccountsPerIP,
MaxAccountsPerIP == 1 ? "" : "s"
MaxAccountsPerIP
);
return null;
}
logger.Information("Login: {0}: Creating new account '{1}'", state, un);
logger.Information("Login: {NetState}: Creating new account '{Username}'", state, un);
var a = new Account(un, pw);
@ -337,7 +337,7 @@ namespace Server.Misc
e.Accepted = false;
e.RejectReason = ALRReason.InUse;
logger.Information("Login: {0}: Past IP limit threshold", e.State);
logger.Information("Login: {NetState}: Past IP limit threshold", e.State);
using var op = new StreamWriter("ipLimits.log", true);
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, Core.Now);
@ -365,28 +365,28 @@ namespace Server.Misc
}
else
{
logger.Information("Login: {0}: Invalid username '{1}'", e.State, un);
logger.Information("Login: {NetState} Invalid username '{Username}'", e.State, un);
e.RejectReason = ALRReason.Invalid;
}
}
else if (!acct.HasAccess(e.State))
{
logger.Information("Login: {0}: Access denied for '{1}'", e.State, un);
logger.Information("Login: {NetState} Access denied for '{Username}'", e.State, un);
e.RejectReason = LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass;
}
else if (!acct.CheckPassword(pw))
{
logger.Information("Login: {0}: Invalid password for '{1}'", e.State, un);
logger.Information("Login: {NetState} Invalid password for '{Username}'", e.State, un);
e.RejectReason = ALRReason.BadPass;
}
else if (acct.Banned)
{
logger.Information("Login: {0}: Banned account '{1}'", e.State, un);
logger.Information("Login: {NetState} Banned account '{Username}'", e.State, un);
e.RejectReason = ALRReason.Blocked;
}
else
{
logger.Information("Login: {0}: Valid credentials for '{1}'", e.State, un);
logger.Information("Login: {NetState} Valid credentials for '{Username}'", e.State, un);
e.State.Account = acct;
e.Accepted = true;
@ -405,7 +405,7 @@ namespace Server.Misc
{
e.Accepted = false;
logger.Warning("Login: {0}: Past IP limit threshold", e.State);
logger.Warning("Login: {NetState} Past IP limit threshold", e.State);
using var op = new StreamWriter("ipLimits.log", true);
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, Core.Now);
@ -422,24 +422,24 @@ namespace Server.Misc
}
else if (!acct.HasAccess(e.State))
{
logger.Information("Login: {0}: Access denied for '{1}'", e.State, un);
logger.Information("Login: {NetState} Access denied for '{Username}'", e.State, un);
e.Accepted = false;
}
else if (!acct.CheckPassword(pw))
{
logger.Information("Login: {0}: Invalid password for '{1}'", e.State, un);
logger.Information("Login: {NetState} Invalid password for '{Username}'", e.State, un);
e.Accepted = false;
}
else if (acct.Banned)
{
logger.Information("Login: {0}: Banned account '{1}'", e.State, un);
logger.Information("Login: {NetState} Banned account '{Username}'", e.State, un);
e.Accepted = false;
}
else
{
acct.LogAccess(e.State);
logger.Information("Login: {0}: Account '{1}' at character list", e.State, un);
logger.Information("Login: {NetState} Account '{Username}' at character list", e.State, un);
e.State.Account = acct;
e.Accepted = true;
e.CityInfo = StartingCities;

View file

@ -73,7 +73,7 @@ namespace Server.Engines.Chat
if (handler == null)
{
state.LogInfo("Unknown chat action 0x{0:X}: {1}", actionID, param);
state.LogInfo($"Unknown chat action 0x{actionID:X}: {param}");
return;
}

View file

@ -26,7 +26,7 @@ namespace Server.Engines.MLQuests.Objectives
if (itemid is <= 0 or > 0x4000)
{
logger.Warning("Cliloc {0} is likely giving the wrong item ID", name.Number);
logger.Warning("Cliloc {Number} is likely giving the wrong item ID", name.Number);
}
}
}

View file

@ -107,13 +107,16 @@ namespace Server.Engines.Spawners
watch.Stop();
logger.Information("Generated {0} spawners ({1:F2} seconds, {2} failures)");
from.SendMessage(
"GenerateSpawners: Generated {0} spawners ({1:F2} seconds, {2} failures)",
logger.Information(
"Generated {Count} spawners ({Duration:F2} seconds, {Failures} failures)",
totalGenerated,
watch.Elapsed.TotalSeconds,
totalFailures
);
from.SendMessage(
$"GenerateSpawners: Generated {totalGenerated} spawners ({watch.Elapsed.TotalSeconds:F2} seconds, {totalFailures} failures)"
);
}
private static void ParseSpawnerList(

View file

@ -31,7 +31,7 @@ public static class AccountPrompt
AccessLevel = AccessLevel.Owner
};
logger.Information("Owner account created: {0}", username);
logger.Information("Owner account created: {Username}", username);
ServerAccess.AddProtectedAccount(a, true);
}
else

View file

@ -138,7 +138,7 @@ namespace Server.Misc
if (newChar == null)
{
logger.Information("Login: {0}: Character creation failed, account full", state);
logger.Information("Login: {NetState}: Character creation failed, account full", state);
return;
}

View file

@ -122,14 +122,14 @@ namespace Server.Misc
if (boxes > 0)
{
logger.Information(
"Cleanup: Detected {0} inaccessible items, including {1} bank boxes, removing..",
"Cleanup: Detected {Count} inaccessible items, including {BankBoxes} bank boxes, removing..",
items.Count,
boxes
);
}
else
{
logger.Information("Cleanup: Detected {0} inaccessible items, removing..", items.Count);
logger.Information("Cleanup: Detected {Count} inaccessible items, removing..", items.Count);
}
for (var i = 0; i < items.Count; ++i)

View file

@ -25,7 +25,7 @@ public static class ServerAccess
{
var username = acct.Username.ToLower();
ServerAccessConfiguration.ProtectedAccounts.Add(username);
logger.Information("Protected account added: {0}", username);
logger.Information("Protected account added: {Username}", username);
if (save)
{
@ -37,7 +37,7 @@ public static class ServerAccess
{
var username = acct.Username.ToLower();
ServerAccessConfiguration.ProtectedAccounts.Remove(username);
logger.Information("Protected account removed: {0}", username);
logger.Information("Protected account removed: {Username}", username);
if (save)
{
@ -59,7 +59,7 @@ public static class ServerAccess
if (ServerAccessConfiguration.ProtectedAccounts.Count > 0)
{
var protectedAccounts = string.Join(", ", ServerAccessConfiguration.ProtectedAccounts);
logger.Information("Protected accounts registered: {0}", protectedAccounts);
logger.Information("Protected accounts registered: {Count}", protectedAccounts);
}
}
@ -85,7 +85,7 @@ public static class ServerAccess
acct.Banned = false;
acct.AccessLevel = AccessLevel.Owner;
logger.Warning("Protected account \"{0}\" has been reset.", username);
logger.Warning("Protected account \"{Username}\" has been reset.", username);
if (e.RejectReason is ALRReason.Blocked or ALRReason.BadPass or ALRReason.BadComm)
{

View file

@ -104,7 +104,7 @@ namespace Server.Misc
if (_publicAddress != null)
{
logger.Information("Auto-detected public IP address ({0})", _publicAddress);
logger.Information("Auto-detected public IP address ({IPAddress})", _publicAddress);
}
else
{

View file

@ -215,11 +215,11 @@ namespace Server.Multis
{
if (value.Count > 2)
{
logger.Warning("More than 2 teleporters detected for {0:X}!", key);
logger.Warning("More than 2 teleporters detected for {ItemId:X}!", key);
}
else if (value.Count <= 1)
{
logger.Warning("1 or less teleporters detected for {0:X}!", key);
logger.Warning("1 or less teleporters detected for {ItemId:X}!", key);
continue;
}

View file

@ -251,7 +251,7 @@ namespace Server.Multis
if (ce != ZlibError.Okay)
{
logger.Warning("ZLib error: {0} (#{1})", ce, (int)ce);
logger.Warning("ZLib error: {Error} (#{ErrorCode})", ce, (int)ce);
length = 0;
size = 0;
}

View file

@ -34,7 +34,7 @@ namespace Server.Network
if (ph.Ingame && state.Mobile == null)
{
state.LogInfo("Sent in-game packet (0x{0:X2}x{1:X2}) before having been attached to a mobile", packetId, cmd);
state.LogInfo($"Sent in-game packet (0x{packetId:X2}x{cmd:X2}) before having been attached to a mobile");
state.Disconnect("Sent in-game packet before being attached to a mobile.");
}
else if (ph.Ingame && state.Mobile.Deleted)

View file

@ -34,7 +34,7 @@ namespace Server.Regions
if (!typeof(BaseGuard).IsAssignableFrom(m_GuardType))
{
logger.Warning("Invalid guard type for region '{0}'", this);
logger.Warning("Invalid guard type for region '{Region}'", this);
m_GuardType = DefaultGuardType;
}
}