Changed default log-folder path, and log-encoding to utf8
This commit is contained in:
parent
89c5f4b820
commit
3167f6c3e6
@ -41,9 +41,10 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
|
|||||||
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
|
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
|
||||||
{
|
{
|
||||||
List<Logger.LoggerType> enabledLoggers = new();
|
List<Logger.LoggerType> enabledLoggers = new();
|
||||||
if(settings.fileLogger.HasValue && settings.fileLogger.Value == true)
|
if(settings.fileLogger is true)
|
||||||
enabledLoggers.Add(Logger.LoggerType.FileLogger);
|
enabledLoggers.Add(Logger.LoggerType.FileLogger);
|
||||||
string? logFilePath = settings.fileLoggerPath ?? "";//TODO path
|
|
||||||
|
string? logFilePath = settings.fileLoggerPath ?? "";
|
||||||
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFilePath);
|
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFilePath);
|
||||||
|
|
||||||
TrangaSettings trangaSettings = new (settings.downloadLocation, settings.workingDirectory, settings.apiPort);
|
TrangaSettings trangaSettings = new (settings.downloadLocation, settings.workingDirectory, settings.apiPort);
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
using System.Text;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Logging;
|
namespace Logging;
|
||||||
|
|
||||||
public class Logger : TextWriter
|
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 override Encoding Encoding { get; }
|
||||||
public enum LoggerType
|
public enum LoggerType
|
||||||
{
|
{
|
||||||
@ -17,13 +21,14 @@ public class Logger : TextWriter
|
|||||||
|
|
||||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
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)
|
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
||||||
_fileLogger = new FileLogger(logFilePath, encoding);
|
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||||
else if(enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is null)
|
else if(enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is null)
|
||||||
{
|
{
|
||||||
_fileLogger = null;
|
logFilePath = Path.Join(LogDirectoryPath,
|
||||||
throw new ArgumentException($"logFilePath can not be null for LoggerType {LoggerType.FileLogger}");
|
$"{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}.log");
|
||||||
|
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
|
if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
|
||||||
|
Loading…
Reference in New Issue
Block a user