From 53d24f29ab8a3560ef58d6d1bb922109a4e0c644 Mon Sep 17 00:00:00 2001 From: MDietermann Date: Mon, 1 Jun 2026 09:41:26 +0200 Subject: [PATCH] feat: add Serilog logging with daily-rolling file sink --- Program.cs | 45 +++++++++++++++++++++++++++++++++++---------- VoxelEngine.csproj | 3 +++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Program.cs b/Program.cs index 6a64379..a16a198 100644 --- a/Program.cs +++ b/Program.cs @@ -1,16 +1,41 @@ using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; +using Serilog; +using Serilog.Events; using VoxelEngine.Core; -NativeWindowSettings nativeSettings = new() -{ - ClientSize = new Vector2i(1280, 720), - Title = "VoxelEngine", - APIVersion = new Version(3, 3), - Profile = ContextProfile.Core, - Flags = ContextFlags.ForwardCompatible -}; +Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .Enrich.FromLogContext() + .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information) + .WriteTo.File( + path: "logs/voxelengine-.log", + rollingInterval: RollingInterval.Day, + retainedFileCountLimit: 14, + outputTemplate: "[{Timestamp:HH:mm:ss.fff} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}") + .CreateLogger(); -using Game game = new(GameWindowSettings.Default, nativeSettings); -game.Run(); +try +{ + NativeWindowSettings nativeSettings = new() + { + ClientSize = new Vector2i(1280, 720), + Title = "VoxelEngine", + APIVersion = new Version(3, 3), + Profile = ContextProfile.Core, + Flags = ContextFlags.ForwardCompatible + }; + + using Game game = new(GameWindowSettings.Default, nativeSettings); + game.Run(); +} +catch (Exception ex) +{ + Log.Fatal(ex, "Unhandled exception at top level"); + throw; +} +finally +{ + Log.CloseAndFlush(); +} diff --git a/VoxelEngine.csproj b/VoxelEngine.csproj index 85ae4e8..49ccd2e 100644 --- a/VoxelEngine.csproj +++ b/VoxelEngine.csproj @@ -10,6 +10,9 @@ + + +