diff --git a/.gitignore b/.gitignore index df6b05c..d54f4d3 100644 --- a/.gitignore +++ b/.gitignore @@ -402,4 +402,5 @@ FodyWeavers.xsd appsettings.local.json CHANGELOG.md Plugins/ -Canvas/ \ No newline at end of file +Canvas/ +Zones/ \ No newline at end of file diff --git a/WFDS.Common/Helpers/ConsoleHelper.cs b/WFDS.Common/Helpers/ConsoleHelper.cs index 971be59..4c79dc8 100644 --- a/WFDS.Common/Helpers/ConsoleHelper.cs +++ b/WFDS.Common/Helpers/ConsoleHelper.cs @@ -1,13 +1,16 @@ -using Serilog; +using Microsoft.Extensions.Logging; +using ZLogger; namespace WFDS.Common.Helpers; public static class ConsoleHelper { + private static readonly ILogger Logger = Log.Factory.CreateLogger(typeof(ConsoleHelper).FullName ?? nameof(ConsoleHelper)); + public static void UpdateConsoleTitle(string name, string code, int cur, int cap) { var title = $"[{cur}/{cap - 1}] {name} [{code}]"; Console.Title = title; - Log.Logger.Information("update console title : {0}", title); + Logger.ZLogInformation($"update console title : {title}"); } } \ No newline at end of file diff --git a/WFDS.Common/Helpers/SteamNetworkingHelper.cs b/WFDS.Common/Helpers/SteamNetworkingHelper.cs index 90df9b8..38bd505 100644 --- a/WFDS.Common/Helpers/SteamNetworkingHelper.cs +++ b/WFDS.Common/Helpers/SteamNetworkingHelper.cs @@ -1,13 +1,16 @@ -using Serilog; +using Microsoft.Extensions.Logging; using Steamworks; using WFDS.Common.Steam; using WFDS.Common.Types; using WFDS.Godot.Binary; +using ZLogger; namespace WFDS.Common.Helpers; public static class SteamNetworkingHelper { + private static readonly ILogger Logger = Log.Factory.CreateLogger(typeof(SteamNetworkingHelper).FullName ?? nameof(SteamNetworkingHelper)); + public static bool SendP2PPacket(CSteamID steamId, NetChannel channel, byte[] bytes) { if (steamId == SteamManager.Inst.SteamId) @@ -27,7 +30,7 @@ public static bool SendP2PPacket(CSteamID steamId, NetChannel channel, byte[] by } catch (Exception ex) { - Log.Logger.Error(ex, "Failed to send P2P packet"); + Logger.ZLogError(ex, $"failed to rent bytes for P2P packet"); return false; } } @@ -60,7 +63,7 @@ public static void BroadcastP2PPacket(CSteamID lobbyId, NetChannel channel, obje } catch (Exception ex) { - Log.Logger.Error(ex, "Failed to rent bytes for broadcast P2P packet"); + Logger.ZLogError($"failed to rent bytes for broadcast P2P packet : \n{ex}"); } } } \ No newline at end of file diff --git a/WFDS.Common/Log.cs b/WFDS.Common/Log.cs new file mode 100644 index 0000000..7d28266 --- /dev/null +++ b/WFDS.Common/Log.cs @@ -0,0 +1,41 @@ +using System.Globalization; +using Microsoft.Extensions.Logging; +using ZLogger; +using ZLogger.Providers; + +namespace WFDS.Common; + +public static class Log +{ + public static readonly ILoggerFactory Factory = LoggerFactory.Create(logging => + { +#if DEBUG + logging.SetMinimumLevel(LogLevel.Debug); +#else + logging.SetMinimumLevel(LogLevel.Information); +#endif + + logging.AddZLoggerConsole(options => + { + options.IncludeScopes = true; + options.UsePlainTextFormatter(formatter => + { + formatter.SetPrefixFormatter($"[{0}] [{1:short}] [{2}] [{3}:{4}] ", (in MessageTemplate template, in LogInfo info) => template.Format(info.Timestamp.Utc.ToString("O"), info.LogLevel, info.Category, info.MemberName, info.LineNumber)); + formatter.SetExceptionFormatter((writer, ex) => Utf8StringInterpolation.Utf8String.Format(writer, $"{ex.Message}")); + }); + }); + + logging.AddZLoggerFile("Logs/latest.log", options => + { + options.UseJsonFormatter(); + }); + logging.AddZLoggerRollingFile(options => + { + options.FilePathSelector = (DateTimeOffset timestamp, int sequenceNumber) => $"logs/{timestamp.ToLocalTime():yyyyMMdd}_{sequenceNumber:000}.log"; + options.RollingInterval = RollingInterval.Day; + options.RollingSizeKB = 1024; + }); + }); + + public static readonly ILogger Logger = Factory.CreateLogger(""); +} \ No newline at end of file diff --git a/WFDS.Common/Network/Packets/ChalkPacket.cs b/WFDS.Common/Network/Packets/ChalkPacket.cs index 1b1fc5f..5872b88 100644 --- a/WFDS.Common/Network/Packets/ChalkPacket.cs +++ b/WFDS.Common/Network/Packets/ChalkPacket.cs @@ -1,12 +1,13 @@ using System.Numerics; -using Serilog; +using Microsoft.Extensions.Logging; using WFDS.Common.Extensions; +using ZLogger; namespace WFDS.Common.Network.Packets; public class ChalkPacket : Packet { - private static readonly ILogger Logger = Log.ForContext(); + private static readonly ILogger Logger = Log.Factory.CreateLogger(); public long CanvasId { get; set; } public List Data { get; set; } = []; @@ -31,7 +32,7 @@ public override void Serialize(Dictionary data) { if (item.Count != 2) { - Logger.Error("invalid chalk packet data"); + Logger.ZLogError($"Invalid chalk data item"); continue; } diff --git a/WFDS.Common/Network/Session.cs b/WFDS.Common/Network/Session.cs index 9da89e6..dba7589 100644 --- a/WFDS.Common/Network/Session.cs +++ b/WFDS.Common/Network/Session.cs @@ -1,5 +1,5 @@ using System.Collections.Concurrent; -using Serilog; +using Microsoft.Extensions.Logging; using Steamworks; using WFDS.Common.Helpers; using WFDS.Common.Types; @@ -8,7 +8,7 @@ namespace WFDS.Common.Network; public sealed class Session(CSteamID steamId) { - private ILogger Logger { get; } = Log.ForContext(); + private ILogger Logger { get; } = Log.Factory.CreateLogger(); public CSteamID SteamId { get; init; } = steamId; public string Name { get; set; } = SteamFriends.GetFriendPersonaName(steamId); public bool HandshakeReceived { get; set; } diff --git a/WFDS.Common/Plugin/PluginManager.cs b/WFDS.Common/Plugin/PluginManager.cs index 9b6fec7..2a2c60d 100644 --- a/WFDS.Common/Plugin/PluginManager.cs +++ b/WFDS.Common/Plugin/PluginManager.cs @@ -1,10 +1,13 @@ using System.Reflection; -using Serilog; +using Microsoft.Extensions.Logging; +using ZLogger; namespace WFDS.Common.Plugin; public static class PluginManager { + private static readonly ILogger Logger = Log.Factory.CreateLogger("PluginManager"); + private static void MakeDirectory() { var path = Path.Join(Directory.GetCurrentDirectory(), "Plugins"); @@ -48,7 +51,7 @@ private static IEnumerable LoadAssembly(string pluginFile) var instance = Activator.CreateInstance(type); if (instance is not Plugin plugin) return null; - Log.Logger.Information("loading plugin {Name} {Version} by {Author}", plugin.Name, plugin.Version, plugin.Author); + Logger.ZLogInformation($"loading plugin {plugin.Name} {plugin.Version} by {plugin.Author}"); plugin.Load(); return plugin; diff --git a/WFDS.Common/Steam/LobbyManager.cs b/WFDS.Common/Steam/LobbyManager.cs index 91f4532..8798e65 100644 --- a/WFDS.Common/Steam/LobbyManager.cs +++ b/WFDS.Common/Steam/LobbyManager.cs @@ -1,8 +1,9 @@ using System.Globalization; -using Serilog; +using Microsoft.Extensions.Logging; using Steamworks; using WFDS.Common.Helpers; using WFDS.Common.Types; +using ZLogger; namespace WFDS.Common.Steam; @@ -29,7 +30,7 @@ public class LobbyManager : Singleton, IDisposable public LobbyManager() { - _logger = Log.ForContext(); + _logger = Log.Factory.CreateLogger(); _lobbyEnterCallback = Callback.Create(OnLobbyEntered); _lobbyCreatedCallback = Callback.Create(OnLobbyCreated); @@ -62,7 +63,7 @@ public void Initialize(string name, GameLobbyType lobbyType, int cap, bool adult _code = RandomHelper.RandomRoomCode(RoomCodeLength); } - _logger.Information("lobby initialized: {Name} {LobbyType} {Cap} {Adult} {Code}", _name, _lobbyType, _cap, _adult, _code); + _logger.ZLogInformation($"lobby initialized: {_name}, {_lobbyType}, {_cap}, {_adult}, {_code}"); } public bool LeaveLobby(out CSteamID lobbyId) @@ -223,12 +224,12 @@ private void OnLobbyCreated(LobbyCreated_t param) { if (param.m_eResult != EResult.k_EResultOK) { - _logger.Error("failed to create lobby: {Result}", param.m_eResult); + _logger.ZLogError($"failed to create lobby: {param.m_eResult}"); return; } var lobbyId = new CSteamID(param.m_ulSteamIDLobby); - _logger.Information("lobby created: {LobbyId}", param.m_ulSteamIDLobby); + _logger.ZLogInformation($"lobby created: {param.m_ulSteamIDLobby}"); UpdateLobbyData(lobbyId); } @@ -236,18 +237,18 @@ private void OnLobbyEntered(LobbyEnter_t param) { if (param.m_EChatRoomEnterResponse != 1) // not success { - _logger.Error("failed to enter lobby: {Result}", param.m_EChatRoomEnterResponse); + _logger.ZLogError($"failed to enter lobby: {param.m_EChatRoomEnterResponse}"); return; } _lobbyId = new CSteamID(param.m_ulSteamIDLobby); - _logger.Information("lobby entered: {LobbyId}", _lobbyId); + _logger.ZLogInformation($"lobby entered: {_lobbyId}"); } private void OnLobbyDataChanged(LobbyDataUpdate_t param) { var lobbyId = new CSteamID(param.m_ulSteamIDLobby); - _logger.Debug("lobby data updated: {LobbyId}", lobbyId); + _logger.ZLogDebug($"lobby data updated: {lobbyId}"); } #endregion diff --git a/WFDS.Common/Steam/SessionManager.cs b/WFDS.Common/Steam/SessionManager.cs index 9aa843d..3c7a1ab 100644 --- a/WFDS.Common/Steam/SessionManager.cs +++ b/WFDS.Common/Steam/SessionManager.cs @@ -1,6 +1,6 @@ using System.Collections.Concurrent; using System.Globalization; -using Serilog; +using Microsoft.Extensions.Logging; using Steamworks; using WFDS.Common.GameEvents; using WFDS.Common.GameEvents.Events; @@ -9,6 +9,7 @@ using WFDS.Common.Network.Packets; using WFDS.Common.Types; using WFDS.Godot.Binary; +using ZLogger; namespace WFDS.Common.Steam; @@ -25,7 +26,7 @@ public sealed class SessionManager : Singleton, IDisposable public SessionManager() { - _logger = Log.ForContext(); + _logger = Log.Factory.CreateLogger(); _lobbyChatUpdateCallback = Callback.Create(OnLobbyChatUpdate); _p2pSessionRequestCallback = Callback.Create(OnP2PSessionRequest); } @@ -66,7 +67,7 @@ public void ServerClose(CSteamID target) return; } - _logger.Information("try server close player: {SteamId}", target); + _logger.ZLogInformation($"try server close player: {target.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); SendP2PPacket(target, NetChannel.GameState, new ServerClosePacket(), false); } @@ -95,35 +96,35 @@ private bool TryCreateSession(CSteamID steamId) { if (_sessions.TryGetValue(steamId.m_SteamID, out _)) { - _logger.Warning("session already exists: {Member}", steamId); + _logger.ZLogWarning($"session already exists: {steamId.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); return false; } if (_banned.Contains(steamId.m_SteamID.ToString(CultureInfo.InvariantCulture))) { - _logger.Warning("banned player: {Member}", steamId); + _logger.ZLogWarning($"banned player: {steamId.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); return false; } - _logger.Information("try create session: {Member}", steamId); + _logger.ZLogInformation($"try create session: {steamId.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); var session = new Session(steamId); if (_sessions.TryAdd(steamId.m_SteamID, session)) { return true; } - _logger.Warning("failed to create session: {Member}", steamId); + _logger.ZLogWarning($"failed to create session: {steamId.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); return false; } private void RemoveSession(CSteamID steamId) { - _logger.Warning("try remove session: {Member}", steamId); + _logger.ZLogWarning($"try remove session: {steamId.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); SteamNetworking.CloseP2PSessionWithUser(steamId); if (!_sessions.TryRemove(steamId.m_SteamID, out _)) { - _logger.Warning("failed to remove session: {Member}", steamId); + _logger.ZLogWarning($"failed to remove session: {steamId.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); return; } @@ -138,7 +139,7 @@ public void KickPlayer(CSteamID target) return; } - _logger.Information("try kick player: {Member}", target); + _logger.ZLogInformation($"try kick player: {target.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); SendP2PPacket(target, NetChannel.GameState, new KickPacket(), false); } @@ -150,7 +151,7 @@ public bool IsBannedPlayer(CSteamID target) public void TempBanPlayer(CSteamID lobbyId, CSteamID target) { - _logger.Information("try ban player: {Member}", target); + _logger.ZLogInformation($"try ban player: {target.m_SteamID.ToString(CultureInfo.InvariantCulture)}"); SendP2PPacket(target, NetChannel.GameState, new BanPacket(), false); BroadcastP2PPacket(lobbyId, NetChannel.GameState, new ForceDisconnectPlayerPacket { UserId = target }, false); @@ -262,7 +263,7 @@ private void OnLobbyChatUpdate(LobbyChatUpdate_t param) var makingChange = new CSteamID(param.m_ulSteamIDMakingChange); var stateChange = (EChatMemberStateChange)param.m_rgfChatMemberStateChange; - _logger.Debug("lobby member state changed: {LobbyId} {ChangedUser} {MakingChange} {StateChange}", lobbyId, changedUser, makingChange, stateChange); + _logger.ZLogDebug($"lobby member state changed: {lobbyId} {changedUser} {makingChange} {stateChange}"); if (stateChange == EChatMemberStateChange.k_EChatMemberStateChangeEntered) { @@ -283,18 +284,18 @@ private void OnLobbyChatUpdate(LobbyChatUpdate_t param) private void OnP2PSessionRequest(P2PSessionRequest_t param) { - _logger.Warning("p2p session request: {SteamId}", param.m_steamIDRemote); + _logger.ZLogWarning($"p2p session request: {param.m_steamIDRemote}"); if (_banned.Contains(param.m_steamIDRemote.m_SteamID.ToString(CultureInfo.InvariantCulture))) { - _logger.Warning("banned player request: {SteamId}", param.m_steamIDRemote); + _logger.ZLogWarning($"banned player request: {param.m_steamIDRemote}"); SteamNetworking.CloseP2PSessionWithUser(param.m_steamIDRemote); return; } if (IsServerClosed()) { - _logger.Warning("server closed: {SteamId}", param.m_steamIDRemote); + _logger.ZLogWarning($"server closed: {param.m_steamIDRemote}"); ServerClose(param.m_steamIDRemote); return; } diff --git a/WFDS.Common/Steam/SteamManager.cs b/WFDS.Common/Steam/SteamManager.cs index b2809e4..baa50f6 100644 --- a/WFDS.Common/Steam/SteamManager.cs +++ b/WFDS.Common/Steam/SteamManager.cs @@ -1,6 +1,7 @@ -using Serilog; +using Microsoft.Extensions.Logging; using Steamworks; using WFDS.Common.Types; +using ZLogger; namespace WFDS.Common.Steam; @@ -9,7 +10,7 @@ public class SteamManager : Singleton public bool Initialized { get; private set; } public CSteamID SteamId => Initialized ? _steamId : CSteamID.Nil; - private readonly ILogger _logger = Log.ForContext(); + private readonly ILogger _logger = Log.Factory.CreateLogger(); private CSteamID _steamId; public bool Init() @@ -19,13 +20,13 @@ public bool Init() var result = SteamAPI.InitEx(out var errMsg); if (result != ESteamAPIInitResult.k_ESteamAPIInitResult_OK) { - _logger.Error("SteamAPI.Init failed: {Result} {Error}", result, errMsg); + _logger.ZLogError($"SteamAPI.Init failed: {result} {errMsg}"); return false; } Initialized = true; _steamId = SteamUser.GetSteamID(); - _logger.Information("SteamAPI.Init success"); + _logger.ZLogInformation($"SteamAPI.Init success"); return true; } diff --git a/WFDS.Common/WFDS.Common.csproj b/WFDS.Common/WFDS.Common.csproj index 1efd7e2..b4e09c4 100644 --- a/WFDS.Common/WFDS.Common.csproj +++ b/WFDS.Common/WFDS.Common.csproj @@ -16,9 +16,9 @@ - + diff --git a/WFDS.Server/Core/Chalk/CanvasManager.cs b/WFDS.Server/Core/Chalk/CanvasManager.cs index 4fd37a0..1ad02b9 100644 --- a/WFDS.Server/Core/Chalk/CanvasManager.cs +++ b/WFDS.Server/Core/Chalk/CanvasManager.cs @@ -1,14 +1,13 @@ using System.Collections.Concurrent; using Microsoft.Extensions.Options; -using Serilog; +using WFDS.Common; using WFDS.Common.Extensions; using WFDS.Common.Network.Packets; using WFDS.Common.Steam; using WFDS.Common.Types; using WFDS.Godot.Binary; using WFDS.Server.Core.Configuration; -using WFDS.Server.Core.Network; -using ILogger = Serilog.ILogger; +using ZLogger; namespace WFDS.Server.Core.Chalk; @@ -17,7 +16,7 @@ internal class CanvasManager(IOptions setting, SessionManager ses private static readonly TimeSpan UpdateInterval = TimeSpan.FromSeconds(10); private static readonly TimeSpan ForceUpdateInterval = TimeSpan.FromSeconds(30); - private static readonly ILogger Logger = Log.ForContext(); + private static readonly ILogger Logger = Log.Factory.CreateLogger(); private ConcurrentDictionary Canvases { get; set; } = []; private bool Updated { get; set; } = true; private DateTimeOffset UpdateTime { get; set; } = DateTimeOffset.UtcNow; @@ -72,7 +71,7 @@ public void SaveChanges() { var fileName = Path.Join(CanvasPath, $"canvas_{item.Key}.bin"); File.WriteAllBytes(fileName, GodotBinaryConverter.Serialize(item.Value.ToPacket().ToDictionary())); - Logger.Information($"saved canvas {item.Key}"); + Logger.ZLogInformation($"saved canvas {item.Key}"); } } @@ -100,7 +99,7 @@ public void LoadAll() Canvases[canvasId] = canvas; } - Logger.Information($"loaded {files.Length} canvas"); + Logger.ZLogInformation($"loaded {files.Length} canvas"); } public void ClearAll() diff --git a/WFDS.Server/Core/GameEvent/GameEventServiceCollectionExtensions.cs b/WFDS.Server/Core/GameEvent/GameEventServiceCollectionExtensions.cs index 8c824d1..2a407e6 100644 --- a/WFDS.Server/Core/GameEvent/GameEventServiceCollectionExtensions.cs +++ b/WFDS.Server/Core/GameEvent/GameEventServiceCollectionExtensions.cs @@ -1,11 +1,14 @@ using Microsoft.Extensions.DependencyInjection.Extensions; -using Serilog; +using WFDS.Common; using WFDS.Common.GameEvents; +using ZLogger; namespace WFDS.Server.Core.GameEvent; internal static class GameEventServiceCollectionExtensions { + private static readonly ILogger Logger = Log.Factory.CreateLogger(typeof(GameEventServiceCollectionExtensions).FullName ?? nameof(GameEventServiceCollectionExtensions)); + public static void AddGameEventHandlers(this IServiceCollection services) { var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); @@ -17,7 +20,7 @@ public static void AddGameEventHandlers(this IServiceCollection services) .Where(type => gameEventHandlerType.IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface) .ToArray(); - Log.Logger.Information("added {Count} game event handlers", gameEventHandlerTypes.Length); + Logger.ZLogInformation($"added {gameEventHandlerTypes.Length} game event handlers"); services.TryAddEnumerable(gameEventHandlerTypes.Select(CreateServiceDescriptor)); } diff --git a/WFDS.Server/Core/Network/PacketHandlerExtensions.cs b/WFDS.Server/Core/Network/PacketHandlerExtensions.cs index a819bf0..3bd97b8 100644 --- a/WFDS.Server/Core/Network/PacketHandlerExtensions.cs +++ b/WFDS.Server/Core/Network/PacketHandlerExtensions.cs @@ -1,11 +1,14 @@ using System.Reflection; -using Serilog; +using WFDS.Common; using WFDS.Common.Network; +using ZLogger; namespace WFDS.Server.Core.Network; internal static class PacketHandlerExtensions { + private static readonly ILogger Logger = Log.Factory.CreateLogger(typeof(PacketHandlerExtensions).FullName ?? nameof(PacketHandlerExtensions)); + public static IServiceCollection AddPacketHandlers(this IServiceCollection service) { var packetHandlerType = typeof(Common.Network.PacketHandler); @@ -17,7 +20,7 @@ public static IServiceCollection AddPacketHandlers(this IServiceCollection servi .Select(x => x.Item2) .Select(service.AddTransient).ToArray().Length; - Log.Logger.Information("added {Count} packet handlers", count); + Logger.ZLogInformation($"added {count} packet handlers"); return service; } } \ No newline at end of file diff --git a/WFDS.Server/Program.cs b/WFDS.Server/Program.cs index d0b226d..c7102f9 100644 --- a/WFDS.Server/Program.cs +++ b/WFDS.Server/Program.cs @@ -1,6 +1,7 @@ using System.Text.Json; using Cysharp.Threading; -using Serilog; +using Steamworks; +using WFDS.Common; using WFDS.Common.Actor; using WFDS.Common.Plugin; using WFDS.Common.Steam; @@ -14,25 +15,15 @@ using WFDS.Server.Core.Network; using WFDS.Server.Core.Utils; using WFDS.Server.Core.Zone; - -Log.Logger = new LoggerConfiguration() - .Enrich.FromLogContext() - .WriteTo.File("Logs/log-.txt", rollingInterval: RollingInterval.Day, retainedFileCountLimit: 3) - .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}") -#if DEBUG - .MinimumLevel.Debug() -#else - .MinimumLevel.Information() -#endif - .CreateLogger(); +using ZLogger; try { SystemMonitor.Start(); LogicLooperPool.InitializeSharedPool(100, Environment.ProcessorCount, RoundRobinLogicLooperPoolBalancer.Instance); - AppDomain.CurrentDomain.UnhandledException += (_, e) => Log.Logger.Fatal(e.ExceptionObject as Exception, "unhandled exception"); - AppDomain.CurrentDomain.ProcessExit += (_, _) => Log.Logger.Information("process exit"); + AppDomain.CurrentDomain.UnhandledException += (_, e) => Log.Logger.ZLogCritical(e.ExceptionObject as Exception, $"unhandled exception"); + AppDomain.CurrentDomain.ProcessExit += (_, _) => Log.Logger.ZLogInformation($"process exit"); var plugins = PluginManager.LoadPlugins(); var builder = WebApplication.CreateBuilder(args); @@ -51,7 +42,9 @@ var setting = section.Get(); ArgumentNullException.ThrowIfNull(setting, nameof(setting)); - builder.Services.AddSerilog(); + builder.Logging.ClearProviders(); + // builder.Logging.AddZLoggerLogProcessor(new LogProcessor()); + builder.Services.AddSingleton(Log.Factory); builder.Services.Configure(section); @@ -99,8 +92,6 @@ plugin.PacketHandlers.ToList().ForEach(x => builder.Services.AddTransient(x)); } - builder.Services.AddSerilog(Log.Logger); - builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); @@ -119,6 +110,7 @@ // server start var app = builder.Build(); + app.Services.GetRequiredService() .ApplicationStopped .Register(() => LogicLooperPool.Shared.ShutdownAsync(TimeSpan.Zero).Wait()); @@ -146,10 +138,10 @@ } catch (Exception ex) { - Log.Logger.Fatal(ex, "Host terminated unexpectedly"); + Log.Logger.ZLogCritical(ex, $"host terminated unexpectedly"); } finally { - await Log.CloseAndFlushAsync(); + Log.Factory.Dispose(); Environment.Exit(0); } \ No newline at end of file diff --git a/WFDS.Server/WFDS.Server.csproj b/WFDS.Server/WFDS.Server.csproj index 890b56e..42a5efb 100644 --- a/WFDS.Server/WFDS.Server.csproj +++ b/WFDS.Server/WFDS.Server.csproj @@ -12,16 +12,11 @@ - - - - - @@ -70,4 +65,8 @@ steam_appid.txt + + + +