diff --git a/SabreTools.Library/Logging/Logger.cs b/SabreTools.Library/Logging/Logger.cs index 3f2d4d4d..14a3e3d2 100644 --- a/SabreTools.Library/Logging/Logger.cs +++ b/SabreTools.Library/Logging/Logger.cs @@ -44,6 +44,17 @@ namespace SabreTools.Library.Logging LoggerImpl.Verbose(this.instance, output); } + /// + /// Write the given verbose progress message to the log output + /// + /// Total count for progress + /// Current count for progres + /// String to be written log + public void Verbose(long total, long current, string output = null) + { + LoggerImpl.Verbose(instance, total, current, output); + } + /// /// Write the given exception as a user message to the log output /// @@ -65,6 +76,17 @@ namespace SabreTools.Library.Logging LoggerImpl.User(this.instance, output); } + /// + /// Write the given user progress message to the log output + /// + /// Total count for progress + /// Current count for progres + /// String to be written log + public void User(long total, long current, string output = null) + { + LoggerImpl.User(instance, total, current, output); + } + /// /// Write the given exception as a warning to the log output /// @@ -86,6 +108,17 @@ namespace SabreTools.Library.Logging LoggerImpl.Warning(this.instance, output); } + /// + /// Write the given warning progress message to the log output + /// + /// Total count for progress + /// Current count for progres + /// String to be written log + public void Warning(long total, long current, string output = null) + { + LoggerImpl.Warning(instance, total, current, output); + } + /// /// Writes the given exception as an error in the log /// @@ -107,6 +140,17 @@ namespace SabreTools.Library.Logging LoggerImpl.Error(this.instance, output); } + /// + /// Write the given error progress message to the log output + /// + /// Total count for progress + /// Current count for progres + /// String to be written log + public void Error(long total, long current, string output = null) + { + LoggerImpl.Error(instance, total, current, output); + } + #endregion } } diff --git a/SabreTools.Library/Logging/LoggerImpl.cs b/SabreTools.Library/Logging/LoggerImpl.cs index bd6a3599..5b5fc64c 100644 --- a/SabreTools.Library/Logging/LoggerImpl.cs +++ b/SabreTools.Library/Logging/LoggerImpl.cs @@ -216,18 +216,18 @@ namespace SabreTools.Library.Logging // Setup the statement based on the inputs string logLine; - if (args.Exception == null) + if (args.Exception != null) { - logLine = args.Statement ?? string.Empty; + logLine = $"{(args.Statement != null ? args.Statement + ": " : string.Empty)}{args.Exception}"; } else if (args.TotalCount != null && args.CurrentCount != null) { - double percentage = (args.CurrentCount.Value / args.TotalCount.Value) * 100; + double percentage = ((double)args.CurrentCount.Value / args.TotalCount.Value) * 100; logLine = $"{percentage:N2}%{(args.Statement != null ? ": " + args.Statement : string.Empty)}"; } else { - logLine = $"{(args.Statement != null ? args.Statement + ": " : string.Empty)}{args.Exception}"; + logLine = args.Statement ?? string.Empty; } // Then write to the log @@ -298,6 +298,18 @@ namespace SabreTools.Library.Logging LogEventHandler(instance, new LogEventArgs(LogLevel.VERBOSE, output, null)); } + /// + /// Write the given verbose progress message to the log output + /// + /// Instance object that's the source of logging + /// Total count for progress + /// Current count for progres + /// String to be written log + internal static void Verbose(object instance, long total, long current, string output = null) + { + LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.VERBOSE, output)); + } + /// /// Write the given exception as a user message to the log output /// @@ -321,6 +333,18 @@ namespace SabreTools.Library.Logging LogEventHandler(instance, new LogEventArgs(LogLevel.USER, output, null)); } + /// + /// Write the given user progress message to the log output + /// + /// Instance object that's the source of logging + /// Total count for progress + /// Current count for progres + /// String to be written log + internal static void User(object instance, long total, long current, string output = null) + { + LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.USER, output)); + } + /// /// Write the given exception as a warning to the log output /// @@ -344,6 +368,18 @@ namespace SabreTools.Library.Logging LogEventHandler(instance, new LogEventArgs(LogLevel.WARNING, output, null)); } + /// + /// Write the given warning progress message to the log output + /// + /// Instance object that's the source of logging + /// Total count for progress + /// Current count for progres + /// String to be written log + internal static void Warning(object instance, long total, long current, string output = null) + { + LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.WARNING, output)); + } + /// /// Writes the given exception as an error in the log /// @@ -367,6 +403,18 @@ namespace SabreTools.Library.Logging LogEventHandler(instance, new LogEventArgs(LogLevel.ERROR, output, null)); } + /// + /// Write the given error progress message to the log output + /// + /// Instance object that's the source of logging + /// Total count for progress + /// Current count for progres + /// String to be written log + internal static void Error(object instance, long total, long current, string output = null) + { + LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.ERROR, output)); + } + #endregion } }