add proper logger, saves to file as well

This commit is contained in:
Master
2023-10-14 19:39:26 +02:00
parent a2e27effff
commit 239c4fca32
17 changed files with 402 additions and 140 deletions

View File

@@ -1,8 +1,10 @@
using AscNet.Logging;
namespace AscNet.SDKServer
{
public class SDKServer
{
public static readonly Common.Util.Logger c = new(nameof(SDKServer), ConsoleColor.Green);
public static readonly Logger log = new(typeof(SDKServer), Logging.LogLevel.DEBUG, Logging.LogLevel.DEBUG);
public static void Main(string[] args)
{
@@ -25,14 +27,14 @@ namespace AscNet.SDKServer
{
controller.GetMethod(nameof(IRegisterable.Register))!.Invoke(null, new object[] { app });
#if DEBUG
c.Log($"Registered HTTP controller '{controller.Name}'");
log.Info($"Registered HTTP controller '{controller.Name}'");
#endif
}
app.UseMiddleware<RequestLoggingMiddleware>();
new Thread(() => app.Run()).Start();
c.Log($"{nameof(SDKServer)} started in port {string.Join(", ", app.Urls.Select(x => x.Split(':').Last()))}!");
log.Info($"{nameof(SDKServer)} started in port {string.Join(", ", app.Urls.Select(x => x.Split(':').Last()))}!");
}
private class RequestLoggingMiddleware
@@ -53,7 +55,7 @@ namespace AscNet.SDKServer
}
finally
{
c.Log($"{context.Response.StatusCode} {context.Request.Method.ToUpper()} {context.Request.Path + context.Request.QueryString}");
log.Info($"{context.Response.StatusCode} {context.Request.Method.ToUpper()} {context.Request.Path + context.Request.QueryString}");
}
}
}