From 2ad04c5c46585fc8516a87c06c37ed21d1ece0de Mon Sep 17 00:00:00 2001 From: Glax Date: Tue, 5 Mar 2024 02:35:37 +0100 Subject: [PATCH] Change LogFilePath to LogFolderPath #139 --- CLI/Program.cs | 4 ++-- Logging/Logger.cs | 14 +++++++------- Tranga/TrangaArgs.cs | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CLI/Program.cs b/CLI/Program.cs index 4bb7182..ec21751 100644 --- a/CLI/Program.cs +++ b/CLI/Program.cs @@ -44,8 +44,8 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings if(settings.fileLogger is true) enabledLoggers.Add(Logger.LoggerType.FileLogger); - string? logFilePath = settings.fileLoggerPath ?? ""; - Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFilePath); + string? logFolderPath = settings.fileLoggerPath ?? ""; + Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFolderPath); TrangaSettings? trangaSettings = null; diff --git a/Logging/Logger.cs b/Logging/Logger.cs index f34bfe1..6ab86b0 100644 --- a/Logging/Logger.cs +++ b/Logging/Logger.cs @@ -20,17 +20,17 @@ public enum LoggerType private readonly FormattedConsoleLogger? _formattedConsoleLogger; private readonly MemoryLogger _memoryLogger; - public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath) + public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFolderPath) { this.Encoding = encoding ?? Encoding.UTF8; - if(enabledLoggers.Contains(LoggerType.FileLogger) && (logFilePath is null || logFilePath == "")) + DateTime now = DateTime.Now; + if(enabledLoggers.Contains(LoggerType.FileLogger) && (logFolderPath is null || logFolderPath == "")) { - DateTime now = DateTime.Now; - logFilePath = Path.Join(LogDirectoryPath, + string filePath = Path.Join(LogDirectoryPath, $"{now.ToShortDateString()}_{now.Hour}-{now.Minute}-{now.Second}.log"); - _fileLogger = new FileLogger(logFilePath, encoding); - }else if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null) - _fileLogger = new FileLogger(logFilePath, encoding); + _fileLogger = new FileLogger(filePath, encoding); + }else if (enabledLoggers.Contains(LoggerType.FileLogger) && logFolderPath is not null) + _fileLogger = new FileLogger(Path.Join(logFolderPath, $"{now.ToShortDateString()}_{now.Hour}-{now.Minute}-{now.Second}.log") , encoding); if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null) diff --git a/Tranga/TrangaArgs.cs b/Tranga/TrangaArgs.cs index 5739316..a4cf2ec 100644 --- a/Tranga/TrangaArgs.cs +++ b/Tranga/TrangaArgs.cs @@ -17,16 +17,16 @@ public static void Main(string[] args) string[]? consoleLogger = GetArg(args, ArgEnum.ConsoleLogger); string[]? fileLogger = GetArg(args, ArgEnum.FileLogger); - string? filePath = GetArg(args, ArgEnum.FileLoggerPath)?[0]; - if (filePath is not null && !Directory.Exists(new FileInfo(filePath).DirectoryName)) - Directory.CreateDirectory(new FileInfo(filePath).DirectoryName!); + string? directoryPath = GetArg(args, ArgEnum.FileLoggerPath)?[0]; + if (directoryPath is not null && !Directory.Exists(directoryPath)) + Directory.CreateDirectory(directoryPath); List enabledLoggers = new(); if(consoleLogger is not null) enabledLoggers.Add(Logger.LoggerType.ConsoleLogger); if (fileLogger is not null) enabledLoggers.Add(Logger.LoggerType.FileLogger); - Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, filePath); + Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, directoryPath); TrangaSettings? settings = null; string[]? downloadLocationPath = GetArg(args, ArgEnum.DownloadLocation); @@ -109,7 +109,7 @@ private static void PrintHelp() { ArgEnum.WorkingDirectory, new(new []{"-w", "--workingDirectory"}, 1, "Directory in which application-data is saved") }, { ArgEnum.ConsoleLogger, new(new []{"-c", "--consoleLogger"}, 0, "Enables the consoleLogger") }, { ArgEnum.FileLogger, new(new []{"-f", "--fileLogger"}, 0, "Enables the fileLogger") }, - { ArgEnum.FileLoggerPath, new (new []{"-l", "--fPath"}, 1, "LogFilePath" ) }, + { ArgEnum.FileLoggerPath, new (new []{"-l", "--fPath"}, 1, "Log Folder Path" ) }, { ArgEnum.Help, new(new []{"-h", "--help"}, 0, "Print this") } //{ ArgEnum., new(new []{""}, 1, "") } };