mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-26 11:19:07 +00:00
Provide logger levels to Logger.Log calls without them
This commit is contained in:
parent
e5bddda7a4
commit
efbd550589
5 changed files with 34 additions and 7 deletions
|
@ -6,6 +6,7 @@ using System.Text.Json;
|
|||
using System.Threading.Tasks;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Match;
|
||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||
|
@ -53,8 +54,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.Log("Exception while parsing MatchData: " + e);
|
||||
Logger.Log("Data: " + bodyString);
|
||||
Logger.Log("Exception while parsing MatchData: " + e, LoggerLevelMatch.Instance);
|
||||
Logger.Log("Data: " + bodyString, LoggerLevelMatch.Instance);
|
||||
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -48,7 +49,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
if (subject.User == null) continue;
|
||||
|
||||
subject.UserId = subject.User.UserId;
|
||||
Logger.Log($"Adding PhotoSubject (userid {subject.UserId}) to db");
|
||||
Logger.Log($"Adding PhotoSubject (userid {subject.UserId}) to db", LoggerLevelPhotos.Instance);
|
||||
|
||||
this.database.PhotoSubjects.Add(subject);
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
|
||||
// photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId);
|
||||
|
||||
Logger.Log($"Adding PhotoSubjectCollection ({photo.PhotoSubjectCollection}) to photo");
|
||||
Logger.Log($"Adding PhotoSubjectCollection ({photo.PhotoSubjectCollection}) to photo", LoggerLevelPhotos.Instance);
|
||||
|
||||
this.database.Photos.Add(photo);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|||
using System.Xml.Serialization;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Files;
|
||||
|
@ -60,11 +61,16 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
FileHelper.EnsureDirectoryCreated(assetsDirectory);
|
||||
if (FileHelper.ResourceExists(hash)) this.Ok(); // no reason to fail if it's already uploaded
|
||||
|
||||
Logger.Log($"Processing resource upload (hash: {hash})");
|
||||
Logger.Log($"Processing resource upload (hash: {hash})", LoggerLevelResources.Instance);
|
||||
LbpFile file = new(await BinaryHelper.ReadFromPipeReader(this.Request.BodyReader));
|
||||
|
||||
if (!FileHelper.IsFileSafe(file)) return this.UnprocessableEntity();
|
||||
if (!FileHelper.IsFileSafe(file))
|
||||
{
|
||||
Logger.Log($"File is unsafe (hash: {hash}, type: {file.FileType})", LoggerLevelResources.Instance);
|
||||
return this.UnprocessableEntity();
|
||||
}
|
||||
|
||||
Logger.Log($"File is OK! (hash: {hash}, type: {file.FileType})", LoggerLevelResources.Instance);
|
||||
await IOFile.WriteAllBytesAsync(path, file.Data);
|
||||
return this.Ok();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,24 @@ namespace LBPUnion.ProjectLighthouse.Logging
|
|||
public override string Name => "Login";
|
||||
}
|
||||
|
||||
public class LoggerLevelResources : LoggerLevel
|
||||
{
|
||||
public static readonly LoggerLevelResources Instance = new();
|
||||
public override string Name => "Resources";
|
||||
}
|
||||
|
||||
public class LoggerLevelMatch : LoggerLevel
|
||||
{
|
||||
public static readonly LoggerLevelMatch Instance = new();
|
||||
public override string Name => "Match";
|
||||
}
|
||||
|
||||
public class LoggerLevelPhotos : LoggerLevel
|
||||
{
|
||||
public static readonly LoggerLevelPhotos Instance = new();
|
||||
public override string Name => "Photos";
|
||||
}
|
||||
|
||||
public class LoggerLevelAspNet : LoggerLevel
|
||||
{
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ namespace LBPUnion.ProjectLighthouse
|
|||
Logger.Log
|
||||
(
|
||||
"The SERVER_DIGEST_KEY environment variable wasn't set, so digest headers won't be set or verified. This will prevent LBP 1 and LBP 3 from working. " +
|
||||
"To increase security, it is recommended that you find and set this variable."
|
||||
"To increase security, it is recommended that you find and set this variable.",
|
||||
LoggerLevelStartup.Instance
|
||||
);
|
||||
computeDigests = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue