fix: fix verbose option

This fixes the broken behaviour of th verbose option by moving logger configuration call options handler
This commit is contained in:
cuqmbr 2022-08-23 13:52:41 +03:00
parent fe01d1ee5c
commit 2f1b2f42f6
4 changed files with 8 additions and 13 deletions

View File

@ -12,6 +12,9 @@ public static class CliOptionsHandlers
FileInfo? outputFile, bool useDatabase, string? sqlQuery,
IEnumerable<FileInfo>? concatFiles, bool isVerbose)
{
RuntimeStorage.IsVerbose = isVerbose;
RuntimeStorage.ConfigureLogger();
Log.Information("Handler started with options: " +
"-i: {input}; -o {output}; -d {useDatabase}; " +
"-q: {sqlQuery}; -c: {concatFiles}; -v: {verbosityLevel}.",

View File

@ -86,8 +86,6 @@ public static class Helpers
{"Dec", 12},
};
Log.Debug("Converting string {dateString} to date...", dateString);
var year = Int32.Parse(dateString.Split(" ")[4]);
var month = monthNameNumber[dateString.Split(" ")[1]];
var day = Int32.Parse(dateString.Split(" ")[2]);
@ -95,8 +93,6 @@ public static class Helpers
var minute = Int32.Parse(dateString.Split(" ")[3].Split(":")[1]);
var second = Int32.Parse(dateString.Split(" ")[3].Split(":")[2]);
Log.Debug("String converted successfully.");
return new DateTime(year, month, day, hour, minute, second);
}

View File

@ -15,12 +15,15 @@ public static class RuntimeStorage
public static void ConfigureLogger()
{
var logLevel =
IsVerbose ? LogEventLevel.Verbose : LogEventLevel.Warning;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console(IsVerbose ? LogEventLevel.Verbose : LogEventLevel.Warning,
.WriteTo.Console(logLevel,
outputTemplate: "{Message:lj}{NewLine}{Exception}")
.WriteTo.File(Path.Join(LogsFolder, "log.txt"),
restrictedToMinimumLevel: IsVerbose ? LogEventLevel.Verbose : LogEventLevel.Warning,
restrictedToMinimumLevel: logLevel,
rollingInterval: RollingInterval.Day)
.CreateLogger();
}

View File

@ -182,13 +182,6 @@ class Program
Arity = ArgumentArity.ZeroOrOne
};
verboseOption.AddValidator(result =>
{
RuntimeStorage.IsVerbose = result.GetValueForOption(verboseOption);
});
RuntimeStorage.ConfigureLogger();
/*----------------------Root Command Setup-------------------------*/
var rootCommand =