diff --git a/src/DotRecast.Recast.Demo/DemoLog.cs b/src/DotRecast.Recast.Demo/DemoLog.cs new file mode 100644 index 0000000..29c4b3a --- /dev/null +++ b/src/DotRecast.Recast.Demo/DemoLog.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using Serilog; +using Silk.NET.OpenGL; + +namespace DotRecast.Recast.Demo; + +public static class DemoLog +{ + private static readonly ILogger Logger = Log.ForContext(typeof(DemoLog)); + private static HashSet messages = new(); + + public static void LogIfGlError(GL gl, [CallerMemberName] string method = "", [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) + { + var err = gl.GetError(); + if (err == GLEnum.NoError) + return; + + var s = $"{method}() err({err}) in {file}:{line}"; + if (messages.Contains(s)) + return; + + messages.Add(s); + Logger.Error(s); + } + +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj index d9f1dc7..f29a100 100644 --- a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj +++ b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj @@ -8,7 +8,10 @@ + + + diff --git a/src/DotRecast.Recast.Demo/Program.cs b/src/DotRecast.Recast.Demo/Program.cs index 5d066e1..a3d3a19 100644 --- a/src/DotRecast.Recast.Demo/Program.cs +++ b/src/DotRecast.Recast.Demo/Program.cs @@ -8,10 +8,6 @@ public static class Program { public static void Main(string[] args) { - Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .MinimumLevel.Verbose() - .CreateLogger(); var path = Loader.ToRPath("dungeon.obj"); path = Path.GetDirectoryName(path); @@ -22,6 +18,16 @@ public static class Program Directory.SetCurrentDirectory(workingDirectory); } + Log.Logger = new LoggerConfiguration() + .Enrich.WithThreadId() + //.Enrich.WithExceptionDetails() + .Enrich.FromLogContext() + //.Enrich.WithMethodFullName() + .MinimumLevel.Verbose() + .WriteTo.File("logs/log.txt") + .WriteTo.Console() + .CreateLogger(); + var demo = new RecastDemo(); demo.start(); }