mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-12 06:27:54 +02:00
Changed default log-folder path, and log-encoding to utf8
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class Logger : TextWriter
|
||||
{
|
||||
private static readonly string LogDirectoryPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
||||
? "/var/log/tranga-api"
|
||||
: Path.Join(Directory.GetCurrentDirectory(), "logs");
|
||||
public override Encoding Encoding { get; }
|
||||
public enum LoggerType
|
||||
{
|
||||
@ -17,13 +21,14 @@ public class Logger : TextWriter
|
||||
|
||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
||||
{
|
||||
this.Encoding = encoding ?? Encoding.ASCII;
|
||||
this.Encoding = encoding ?? Encoding.UTF8;
|
||||
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
||||
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||
else if(enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is null)
|
||||
{
|
||||
_fileLogger = null;
|
||||
throw new ArgumentException($"logFilePath can not be null for LoggerType {LoggerType.FileLogger}");
|
||||
logFilePath = Path.Join(LogDirectoryPath,
|
||||
$"{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}.log");
|
||||
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||
}
|
||||
|
||||
if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
|
||||
|
Reference in New Issue
Block a user