Replace all Console.WriteLine instances with Logger.Log

This commit is contained in:
jvyden 2021-10-21 01:16:25 -04:00
commit 847ba3da0c
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 17 additions and 4 deletions

View file

@ -11,6 +11,11 @@ namespace LBPUnion.ProjectLighthouse.Logging {
public static LoggerLevelDatabase Instance = new();
}
public class LoggerLevelHttp : LoggerLevel {
public override string Name => "HTTP";
public static LoggerLevelDatabase Instance = new();
}
#region ASP.NET
public class LoggerLevelAspNetTrace : LoggerLevel {
public override string Name => "ASP.NET: Trace";

View file

@ -9,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
namespace LBPUnion.ProjectLighthouse {
public static class Program {

View file

@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using Kettu;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Serialization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@ -43,10 +45,15 @@ namespace LBPUnion.ProjectLighthouse {
await next(); // Handle the request so we can get the status code from it
requestStopwatch.Stop();
Console.WriteLine($"{context.Response.StatusCode}, {requestStopwatch.ElapsedMilliseconds}ms: {context.Request.Method} {context.Request.Path}{context.Request.QueryString}");
Logger.Log(
$"{context.Response.StatusCode}, {requestStopwatch.ElapsedMilliseconds}ms: {context.Request.Method} {context.Request.Path}{context.Request.QueryString}",
LoggerLevelHttp.Instance
);
if(context.Request.Method == "POST") {
context.Request.Body.Position = 0;
Console.WriteLine(await new StreamReader(context.Request.Body).ReadToEndAsync());
Logger.Log(await new StreamReader(context.Request.Body).ReadToEndAsync(), LoggerLevelHttp.Instance);
}
});

View file

@ -1,5 +1,7 @@
#nullable enable
using System;
using Kettu;
using LBPUnion.ProjectLighthouse.Logging;
namespace LBPUnion.ProjectLighthouse.Types.Settings {
public static class ServerSettings {
@ -29,7 +31,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings {
return new Database().Database.CanConnect();
}
catch(Exception e) {
Console.WriteLine(e);
Logger.Log(e.ToString(), LoggerLevelDatabase.Instance);
return false;
}
}