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

@ -343,13 +343,7 @@ public partial class NetState : IComparable<NetState>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LogInfo(string text)
{
logger.Information("Client: {0}: {1}", this, text);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LogInfo(string format, params object[] args)
{
LogInfo(string.Format(format, args));
logger.Information("Client: {NetState}: {Message}", this, text);
}
public void AddMenu(IMenu menu)
@ -861,7 +855,7 @@ public partial class NetState : IComparable<NetState>
{
if (ex.SocketErrorCode != SocketError.WouldBlock)
{
logger.Debug(ex, "Disconnected due to socket exception");
logger.Debug(ex, "Disconnected due to a socket exception");
Disconnect(string.Empty);
}
}
@ -1127,13 +1121,6 @@ public partial class NetState : IComparable<NetState>
var count = TcpServer.Instances.Count;
if (a != null)
{
LogInfo("Disconnected. [{0} Online] [{1}]", count, a);
}
else
{
LogInfo("Disconnected. [{0} Online]", count);
}
LogInfo(a != null ? $"Disconnected. [{count} Online] [{a}]" : $"Disconnected. [{count} Online]");
}
}

View file

@ -103,8 +103,7 @@ public static class IncomingExtendedCommandPackets
if (state.Mobile == null)
{
state.LogInfo(
"Sent in-game packet (0xBFx{0:X2}) before having been attached to a mobile",
packetId
$"Sent in-game packet (0xBFx{packetId:X2}) before having been attached to a mobile"
);
}

View file

@ -202,7 +202,7 @@ public static class IncomingPlayerPackets
}
default:
{
state.LogInfo("Unknown text-command type 0x{0:X2}: {1}", state, type, command);
state.LogInfo($"Unknown text-command type 0x{state:X2}: {type} ({command})");
break;
}
}

View file

@ -78,7 +78,7 @@ public static class OutgoingGumpPackets
if (error != ZlibError.Okay)
{
logger.Warning($"Gump compression failed {error}");
logger.Warning("Gump compression failed: {Error}", error);
writer.Write(4);
writer.Write(0);

View file

@ -77,7 +77,7 @@ namespace Server.Network
foreach (var ipep in listeningAddresses)
{
logger.Information("Listening: {0}:{1}", ipep.Address, ipep.Port);
logger.Information("Listening: {Address}:{Port}", ipep.Address, ipep.Port);
}
ListeningAddresses = listeningAddresses.ToArray();
@ -119,12 +119,12 @@ namespace Server.Network
// WSAEADDRINUSE
if (se.ErrorCode == 10048)
{
logger.Warning("Listener: {0}:{1}: Failed (In Use)", ipep.Address, ipep.Port);
logger.Warning("Listener: {Address}:{Port}: Failed (In Use)", ipep.Address, ipep.Port);
}
// WSAEADDRNOTAVAIL
else if (se.ErrorCode == 10049)
{
logger.Warning("Listener {0}:{1}: Failed (Unavailable)", ipep.Address, ipep.Port);
logger.Warning("Listener {Address}:{Port}: Failed (Unavailable)", ipep.Address, ipep.Port);
}
else
{
@ -142,7 +142,7 @@ namespace Server.Network
while (++count <= MaxConnectionsPerLoop && _connectedQueue.TryDequeue(out var ns))
{
Instances.Add(ns);
ns.LogInfo("Connected. [{0} Online]", Instances.Count);
ns.LogInfo($"Connected. [{Instances.Count} Online]");
}
}
@ -166,7 +166,7 @@ namespace Server.Network
if (socket.RemoteEndPoint is IPEndPoint ipep)
{
var ip = ipep.Address.ToString();
logger.Warning("Listener {0}: Failed (Maximum connections reached)", ip);
logger.Warning("Listener {Address}: Failed (Maximum connections reached)", ip);
NetState.TraceDisconnect("Maximum connections reached.", ip);
}