forked from bit/DotRecastNetSim
add file logger
This commit is contained in:
parent
5da16c6f94
commit
e6f6d190c1
|
@ -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<string> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,10 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
|
||||
<PackageReference Include="Silk.NET" Version="2.16.0" />
|
||||
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue