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:
parent
5e1ec5416d
commit
3a619e0103
29 changed files with 347 additions and 176 deletions
|
|
@ -20,11 +20,14 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using Server.Logging;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public static class TcpServer
|
||||
{
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(TcpServer));
|
||||
|
||||
private const int MaxConnectionsPerLoop = 250;
|
||||
|
||||
// Sanity. 256 * 1024 * 4096 = ~1.3GB of ram
|
||||
|
|
@ -75,7 +78,7 @@ namespace Server.Network
|
|||
|
||||
foreach (var ipep in listeningAddresses)
|
||||
{
|
||||
Console.WriteLine("Listening: {0}:{1}", ipep.Address, ipep.Port);
|
||||
logger.Information("Listening: {0}:{1}", ipep.Address, ipep.Port);
|
||||
}
|
||||
|
||||
ListeningAddresses = listeningAddresses.ToArray();
|
||||
|
|
@ -104,17 +107,16 @@ namespace Server.Network
|
|||
// WSAEADDRINUSE
|
||||
if (se.ErrorCode == 10048)
|
||||
{
|
||||
Console.WriteLine("Listener: {0}:{1}: Failed (In Use)", ipep.Address, ipep.Port);
|
||||
logger.Warning("Listener: {0}:{1}: Failed (In Use)", ipep.Address, ipep.Port);
|
||||
}
|
||||
// WSAEADDRNOTAVAIL
|
||||
else if (se.ErrorCode == 10049)
|
||||
{
|
||||
Console.WriteLine("Listener {0}:{1}: Failed (Unavailable)", ipep.Address, ipep.Port);
|
||||
logger.Warning("Listener {0}:{1}: Failed (Unavailable)", ipep.Address, ipep.Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Listener Exception:");
|
||||
Console.WriteLine(se);
|
||||
logger.Warning(se, "Listener Exception:");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +130,7 @@ namespace Server.Network
|
|||
while (++count <= MaxConnectionsPerLoop && _connectedQueue.TryDequeue(out var ns))
|
||||
{
|
||||
Instances.Add(ns);
|
||||
ns.WriteConsole("Connected. [{0} Online]", Instances.Count);
|
||||
ns.LogInfo("Connected. [{0} Online]", Instances.Count);
|
||||
ns.Start();
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +156,7 @@ namespace Server.Network
|
|||
if (socket.RemoteEndPoint is IPEndPoint ipep)
|
||||
{
|
||||
var ip = ipep.Address.ToString();
|
||||
Console.WriteLine("Listener {0}: Failed (Maximum connections reached)", ip);
|
||||
logger.Warning("Listener {0}: Failed (Maximum connections reached)", ip);
|
||||
NetState.TraceDisconnect("Maximum connections reached.", ip);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue