feat(logging): Adds support for Serilog (#573)

Example:
```cs
public class SomeClass
{
  private static ILogger _logger;
  private static Logger => _logger ??= LogFactory.GetLogger(typeof(SomeClass));
  ...
}
```
This commit is contained in:
Pedro Pardal 2021-04-20 08:43:54 +02:00 committed by GitHub
parent 5e1ec5416d
commit 3a619e0103
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 347 additions and 176 deletions

View file

@ -17,7 +17,6 @@ using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
@ -28,6 +27,7 @@ using Server.Diagnostics;
using Server.Gumps;
using Server.HuePickers;
using Server.Items;
using Server.Logging;
using Server.Menus;
namespace Server.Network
@ -39,6 +39,8 @@ namespace Server.Network
public partial class NetState : IComparable<NetState>
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(NetState));
private const int RecvPipeSize = 1024 * 64;
private const int SendPipeSize = 1024 * 256;
private static int GumpCap = 512;
@ -343,15 +345,15 @@ namespace Server.Network
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteConsole(string text)
public void LogInfo(string text)
{
Console.WriteLine("Client: {0}: {1}", this, text);
logger.Information("Client: {0}: {1}", this, text);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteConsole(string format, params object[] args)
public void LogInfo(string format, params object[] args)
{
WriteConsole(string.Format(format, args));
LogInfo(string.Format(format, args));
}
public void AddMenu(IMenu menu)
@ -364,7 +366,7 @@ namespace Server.Network
}
else
{
WriteConsole("Exceeded menu cap, disconnecting...");
LogInfo("Exceeded menu cap, disconnecting...");
Disconnect("Exceeded menu cap.");
}
}
@ -394,7 +396,7 @@ namespace Server.Network
}
else
{
WriteConsole("Exceeded hue picker cap, disconnecting...");
LogInfo("Exceeded hue picker cap, disconnecting...");
Disconnect("Exceeded hue picker cap.");
}
}
@ -424,7 +426,7 @@ namespace Server.Network
}
else
{
WriteConsole("Exceeded gump cap, disconnecting...");
LogInfo("Exceeded gump cap, disconnecting...");
Disconnect("Exceeded gump cap.");
}
}
@ -622,7 +624,7 @@ namespace Server.Network
{
if (packetId != 0xCF && packetId != 0x80)
{
WriteConsole("Possible encrypted client detected, disconnecting...");
LogInfo("Possible encrypted client detected, disconnecting...");
HandleError(packetId, packetLength);
return true;
}
@ -740,7 +742,7 @@ namespace Server.Network
PacketHandler handler = GetHandler(packetId);
if (handler == null)
{
WriteConsole($"received unknown packet 0x{packetId:X2} while in state {_protocolState}");
LogInfo($"received unknown packet 0x{packetId:X2} while in state {_protocolState}");
packetLength = length;
return ParserState.Error;
}
@ -771,7 +773,7 @@ namespace Server.Network
{
if (Mobile == null)
{
WriteConsole($"received packet 0x{packetId:X2} before having been attached to a mobile");
LogInfo($"received packet 0x{packetId:X2} before having been attached to a mobile");
return ParserState.Error;
}
@ -1015,7 +1017,7 @@ namespace Server.Network
{
if (Connection != null && _nextActivityCheck - curTicks < 0)
{
WriteConsole("Disconnecting due to inactivity...");
LogInfo("Disconnecting due to inactivity...");
Disconnect("Disconnecting due to inactivity.");
}
}
@ -1147,11 +1149,11 @@ namespace Server.Network
if (a != null)
{
WriteConsole("Disconnected. [{0} Online] [{1}]", count, a);
LogInfo("Disconnected. [{0} Online] [{1}]", count, a);
}
else
{
WriteConsole("Disconnected. [{0} Online]", count);
LogInfo("Disconnected. [{0} Online]", count);
}
}
}