feat: add Serilog logging with daily-rolling file sink
This commit is contained in:
45
Program.cs
45
Program.cs
@@ -1,16 +1,41 @@
|
|||||||
using OpenTK.Mathematics;
|
using OpenTK.Mathematics;
|
||||||
using OpenTK.Windowing.Common;
|
using OpenTK.Windowing.Common;
|
||||||
using OpenTK.Windowing.Desktop;
|
using OpenTK.Windowing.Desktop;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
using VoxelEngine.Core;
|
using VoxelEngine.Core;
|
||||||
|
|
||||||
NativeWindowSettings nativeSettings = new()
|
Log.Logger = new LoggerConfiguration()
|
||||||
{
|
.MinimumLevel.Debug()
|
||||||
ClientSize = new Vector2i(1280, 720),
|
.Enrich.FromLogContext()
|
||||||
Title = "VoxelEngine",
|
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information)
|
||||||
APIVersion = new Version(3, 3),
|
.WriteTo.File(
|
||||||
Profile = ContextProfile.Core,
|
path: "logs/voxelengine-.log",
|
||||||
Flags = ContextFlags.ForwardCompatible
|
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);
|
try
|
||||||
game.Run();
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="OpenTK" Version="4.9.4" />
|
<PackageReference Include="OpenTK" Version="4.9.4" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.3.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
<PackageReference Include="StbImageSharp" Version="2.30.15" />
|
<PackageReference Include="StbImageSharp" Version="2.30.15" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user