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

@ -26,12 +26,15 @@ using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Server.Json;
using Server.Logging;
using Server.Network;
namespace Server
{
public static class Core
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(Core));
private static bool _crashed;
private static Thread _timerThread;
private static string _baseDirectory;
@ -297,7 +300,7 @@ namespace Server
_ => "CTRL+C"
};
WriteConsoleLine($"Detected {keypress} pressed.");
logger.Information($"Detected {keypress} pressed.");
e.Cancel = true;
Kill();
}
@ -410,7 +413,7 @@ namespace Server
".TrimMultiline());
Utility.PopColor();
WriteConsoleLine($"Running on {RuntimeInformation.FrameworkDescription}");
logger.Information($"Running on {RuntimeInformation.FrameworkDescription}");
var ttObj = new Timer.TimerThread();
_timerThread = new Thread(ttObj.TimerMain)
@ -422,7 +425,7 @@ namespace Server
if (s.Length > 0)
{
WriteConsoleLine($"Running with arguments: {s}");
logger.Information($"Running with arguments: {s}");
}
ProcessorCount = Environment.ProcessorCount;
@ -434,17 +437,17 @@ namespace Server
if (MultiProcessor)
{
WriteConsoleLine($"Optimizing for {ProcessorCount} processor{(ProcessorCount == 1 ? "" : "s")}");
logger.Information($"Optimizing for {ProcessorCount} processor{(ProcessorCount == 1 ? "" : "s")}");
}
Console.CancelKeyPress += Console_CancelKeyPressed;
if (GCSettings.IsServerGC)
{
WriteConsoleLine(": Server garbage collection mode enabled");
logger.Information("Server garbage collection mode enabled");
}
WriteConsoleLine($"High resolution timing ({(Stopwatch.IsHighResolution ? "Supported" : "Unsupported")})");
logger.Information($"High resolution timing ({(Stopwatch.IsHighResolution ? "Supported" : "Unsupported")})");
ServerConfiguration.Load();
@ -605,17 +608,5 @@ namespace Server
Parallel.ForEach(assembly.GetTypes(), VerifyType);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteConsole(string message)
{
Console.Write("Core: {0}", message);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void WriteConsoleLine(string message)
{
Console.WriteLine("Core: {0}", message);
}
}
}