WriteToLogFile now implemented

This commit is contained in:
Alex
2025-02-09 17:46:18 +00:00
parent 955e44eb62
commit c67c807dd3
8 changed files with 37 additions and 10 deletions
@@ -12,7 +12,6 @@ using Core.Utils;
using Core.Utils.Cloners;
using SptCommon.Annotations;
using SptCommon.Extensions;
using BodyPartHealth = Core.Models.Eft.Common.Tables.BodyPartHealth;
namespace Core.Controllers;
+1 -1
View File
@@ -14,6 +14,6 @@ public interface ISptLogger<T>
void Info(string data, Exception? ex = null);
void Debug(string data, Exception? ex = null);
void Critical(string data, Exception? ex = null);
void WriteToLogFile(string body);
void WriteToLogFile(string body, LogLevel level = LogLevel.Info);
bool IsLogEnabled(LogLevel level);
}
@@ -0,0 +1,6 @@
namespace Core.Utils.Logger;
// This is a dummy class to use for SourceContext in Serilog, do not remove!
public class FileLogger
{
}
+8 -3
View File
@@ -2,6 +2,7 @@ using SptCommon.Annotations;
using Core.Models.Eft.ItemEvent;
using Core.Models.Logging;
using Core.Models.Utils;
using Core.Utils.Logger;
using LogLevel = Core.Models.Spt.Logging.LogLevel;
namespace Server.Logger;
@@ -10,10 +11,15 @@ namespace Server.Logger;
public class SptWebApplicationLogger<T> : ISptLogger<T>
{
private ILogger _logger;
private static ILogger? _fileLogger;
public SptWebApplicationLogger(ILoggerProvider provider)
{
_logger = provider.CreateLogger(typeof(T).FullName ?? "SPT Logger Default Name");
if (_fileLogger == null)
{
_fileLogger = provider.CreateLogger(typeof(FileLogger).FullName ?? "SPT Logger Default Name");
}
}
public void LogWithColor(
@@ -77,10 +83,9 @@ public class SptWebApplicationLogger<T> : ISptLogger<T>
_logger.LogCritical(ex, GetColorizedText(data, LogTextColor.Black, LogBackgroundColor.Red));
}
public void WriteToLogFile(string data)
public void WriteToLogFile(string body, LogLevel level = LogLevel.Info)
{
//TODO - implement + turn object into json
_logger.LogError("NOT IMPLEMENTED - WriteToLogFile");
_fileLogger?.Log(ConvertLogLevel(level), body);
}
public bool IsLogEnabled(LogLevel level)
+19 -2
View File
@@ -28,9 +28,26 @@
],
"WriteTo": [
{
"Name": "Console",
"Name": "Logger",
"Args": {
"formatter": "Server.Logger.ConsoleFormatter::Default, Server"
"configureLogger": {
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "StartsWith(SourceContext, 'Core.Utils.Logger.FileLogger')"
}
}
],
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Server.Logger.ConsoleFormatter::Default, Server"
}
}
]
}
}
},
{
@@ -50,7 +50,7 @@ public class SptBasicLogger<T> : ISptLogger<T>
Console.WriteLine($"{categoryName}: {data}");
}
public void WriteToLogFile(string body)
public void WriteToLogFile(string body, LogLevel level = LogLevel.Info)
{
Console.WriteLine($"{categoryName}: {body}");
}
+1 -1
View File
@@ -51,7 +51,7 @@ public class SptBasicLogger<T> : ISptLogger<T>
Console.WriteLine($"{categoryName}: {data}");
}
public void WriteToLogFile(string body)
public void WriteToLogFile(string body, LogLevel level = LogLevel.Info)
{
Console.WriteLine($"{categoryName}: {body}");
}
+1 -1
View File
@@ -51,7 +51,7 @@ public class MockLogger<T> : ISptLogger<T>
Console.WriteLine(data);
}
public void WriteToLogFile(string body)
public void WriteToLogFile(string body, LogLevel level = LogLevel.Info)
{
throw new NotImplementedException();
}