Merge branch 'main' into develop
# Conflicts: # Server/Logger/WebApplicationLogger.cs
This commit is contained in:
@@ -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
|
||||
{
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Core.Models.Logging;
|
||||
using Core.Models.Utils;
|
||||
using Core.Utils.Logger;
|
||||
using SptCommon.Annotations;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
@@ -8,11 +9,17 @@ namespace Server.Logger;
|
||||
[Injectable]
|
||||
public class SptWebApplicationLogger<T> : ISptLogger<T>
|
||||
{
|
||||
|
||||
private readonly 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(
|
||||
@@ -62,10 +69,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
@@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user