add file logger

This commit is contained in:
ikpil 2023-03-19 14:39:44 +09:00
parent 5da16c6f94
commit e6f6d190c1
3 changed files with 40 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -8,7 +8,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Serilog" Version="2.12.0" /> <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.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" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" /> <PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" />
</ItemGroup> </ItemGroup>

View File

@ -8,10 +8,6 @@ public static class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Verbose()
.CreateLogger();
var path = Loader.ToRPath("dungeon.obj"); var path = Loader.ToRPath("dungeon.obj");
path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path);
@ -22,6 +18,16 @@ public static class Program
Directory.SetCurrentDirectory(workingDirectory); 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(); var demo = new RecastDemo();
demo.start(); demo.start();
} }