diff --git a/SabreTools.Logging/LogEventArgs.cs b/SabreTools.Logging/LogEventArgs.cs index ce91d6e6..00d5186b 100644 --- a/SabreTools.Logging/LogEventArgs.cs +++ b/SabreTools.Logging/LogEventArgs.cs @@ -15,32 +15,50 @@ namespace SabreTools.Logging /// /// LogLevel for the event /// - public LogLevel LogLevel { get; set; } = LogLevel.VERBOSE; + public readonly LogLevel LogLevel; /// /// Log statement to be printed /// - public string? Statement { get; set; } = null; + public readonly string? Statement = null; /// /// Exception to be passed along to the event handler /// - public Exception? Exception { get; set; } = null; + public readonly Exception? Exception = null; /// /// Total count for progress log events /// - public long? TotalCount { get; set; } = null; + public readonly long? TotalCount = null; /// /// Current count for progress log events /// - public long? CurrentCount { get; set; } = null; + public readonly long? CurrentCount = null; + + /// + /// Statement constructor + /// + public LogEventArgs(LogLevel logLevel, string statement) + { + LogLevel = logLevel; + Statement = statement; + } + + /// + /// Statement constructor + /// + public LogEventArgs(LogLevel logLevel, Exception exception) + { + LogLevel = logLevel; + Exception = exception; + } /// /// Statement and exception constructor /// - public LogEventArgs(LogLevel logLevel = LogLevel.VERBOSE, string? statement = null, Exception? exception = null) + public LogEventArgs(LogLevel logLevel, string statement, Exception exception) { LogLevel = logLevel; Statement = statement; @@ -50,7 +68,7 @@ namespace SabreTools.Logging /// /// Progress constructor /// - public LogEventArgs(long total, long current, LogLevel logLevel = LogLevel.VERBOSE, string? statement = null) + public LogEventArgs(long total, long current, LogLevel logLevel, string? statement = null) { LogLevel = logLevel; Statement = statement; diff --git a/SabreTools.Logging/Logger.cs b/SabreTools.Logging/Logger.cs index 7ac3c694..d16b6c89 100644 --- a/SabreTools.Logging/Logger.cs +++ b/SabreTools.Logging/Logger.cs @@ -23,16 +23,7 @@ namespace SabreTools.Logging #region Log Event Triggers - /// - /// Write the given exception as a verbose message to the log output - /// - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public void Verbose(Exception ex, string? output = null) - { - LoggerImpl.Verbose(_instance, ex, output); - } + #region Verbose /// /// Write the given string as a verbose message to the log output @@ -40,9 +31,24 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public void Verbose(string output) - { - LoggerImpl.Verbose(_instance, output); - } + => LoggerImpl.Verbose(_instance, output); + + /// + /// Write the given exception as a verbose message to the log output + /// + /// Exception to be written log + /// True if the output could be written, false otherwise + public void Verbose(Exception ex) + => LoggerImpl.Verbose(_instance, ex); + + /// + /// Write the given exception and string as a verbose message to the log output + /// + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public void Verbose(Exception ex, string output) + => LoggerImpl.Verbose(_instance, ex, output); /// /// Write the given verbose progress message to the log output @@ -51,20 +57,11 @@ namespace SabreTools.Logging /// 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); - } + => LoggerImpl.Verbose(_instance, total, current, output); - /// - /// Write the given exception as a user message to the log output - /// - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public void User(Exception ex, string? output = null) - { - LoggerImpl.User(_instance, ex, output); - } + #endregion + + #region User /// /// Write the given string as a user message to the log output @@ -72,9 +69,24 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public void User(string output) - { - LoggerImpl.User(_instance, output); - } + => LoggerImpl.User(_instance, output); + + /// + /// Write the given exception as a user message to the log output + /// + /// Exception to be written log + /// True if the output could be written, false otherwise + public void User(Exception ex) + => LoggerImpl.User(_instance, ex); + + /// + /// Write the given exception and string as a user message to the log output + /// + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public void User(Exception ex, string output) + => LoggerImpl.User(_instance, ex, output); /// /// Write the given user progress message to the log output @@ -83,20 +95,11 @@ namespace SabreTools.Logging /// 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); - } + => LoggerImpl.User(_instance, total, current, output); - /// - /// Write the given exception as a warning to the log output - /// - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public void Warning(Exception ex, string? output = null) - { - LoggerImpl.Warning(_instance, ex, output); - } + #endregion + + #region Warning /// /// Write the given string as a warning to the log output @@ -104,9 +107,24 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public void Warning(string output) - { - LoggerImpl.Warning(_instance, output); - } + => LoggerImpl.Warning(_instance, output); + + /// + /// Write the given exception as a warning to the log output + /// + /// Exception to be written log + /// True if the output could be written, false otherwise + public void Warning(Exception ex) + => LoggerImpl.Warning(_instance, ex); + + /// + /// Write the given exception and string as a warning to the log output + /// + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public void Warning(Exception ex, string output) + => LoggerImpl.Warning(_instance, ex, output); /// /// Write the given warning progress message to the log output @@ -115,20 +133,11 @@ namespace SabreTools.Logging /// 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); - } + => LoggerImpl.Warning(_instance, total, current, output); - /// - /// Writes the given exception as an error in the log - /// - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public void Error(Exception ex, string? output = null) - { - LoggerImpl.Error(_instance, ex, output); - } + #endregion + + #region Error /// /// Writes the given string as an error in the log @@ -136,9 +145,24 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public void Error(string output) - { - LoggerImpl.Error(_instance, output); - } + => LoggerImpl.Error(_instance, output); + + /// + /// Writes the given exception as an error in the log + /// + /// Exception to be written log + /// True if the output could be written, false otherwise + public void Error(Exception ex) + => LoggerImpl.Error(_instance, ex); + + /// + /// Writes the given exception and string as an error in the log + /// + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public void Error(Exception ex, string output) + => LoggerImpl.Error(_instance, ex, output); /// /// Write the given error progress message to the log output @@ -147,9 +171,9 @@ namespace SabreTools.Logging /// 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); - } + => LoggerImpl.Error(_instance, total, current, output); + + #endregion #endregion } diff --git a/SabreTools.Logging/LoggerImpl.cs b/SabreTools.Logging/LoggerImpl.cs index 6e1f2d2f..7da2ef13 100644 --- a/SabreTools.Logging/LoggerImpl.cs +++ b/SabreTools.Logging/LoggerImpl.cs @@ -285,17 +285,7 @@ namespace SabreTools.Logging #region Log Event Triggers - /// - /// Write the given exception as a verbose message to the log output - /// - /// Instance object that's the source of logging - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public static void Verbose(object? instance, Exception ex, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.VERBOSE, output, ex)); - } + #region Verbose /// /// Write the given string as a verbose message to the log output @@ -304,9 +294,26 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public static void Verbose(object? instance, string output) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.VERBOSE, output, null)); - } + => LogEventHandler(instance, new LogEventArgs(LogLevel.VERBOSE, output)); + + /// + /// Write the given exception as a verbose message to the log output + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// True if the output could be written, false otherwise + public static void Verbose(object? instance, Exception ex) + => LogEventHandler(instance, new LogEventArgs(LogLevel.VERBOSE, ex)); + + /// + /// Write the given exception and string as a verbose message to the log output + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public static void Verbose(object? instance, Exception ex, string output) + => LogEventHandler(instance, new LogEventArgs(LogLevel.VERBOSE, output, ex)); /// /// Write the given verbose progress message to the log output @@ -316,21 +323,11 @@ namespace SabreTools.Logging /// Current count for progres /// String to be written log public static void Verbose(object? instance, long total, long current, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.VERBOSE, output)); - } + => LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.VERBOSE, output)); - /// - /// Write the given exception as a user message to the log output - /// - /// Instance object that's the source of logging - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public static void User(object? instance, Exception ex, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.USER, output, ex)); - } + #endregion + + #region User /// /// Write the given string as a user message to the log output @@ -339,9 +336,26 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public static void User(object? instance, string output) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.USER, output, null)); - } + => LogEventHandler(instance, new LogEventArgs(LogLevel.USER, output)); + + /// + /// Write the given exception as a user message to the log output + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// True if the output could be written, false otherwise + public static void User(object? instance, Exception ex) + => LogEventHandler(instance, new LogEventArgs(LogLevel.USER, ex)); + + /// + /// Write the given exception and string as a user message to the log output + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public static void User(object? instance, Exception ex, string output) + => LogEventHandler(instance, new LogEventArgs(LogLevel.USER, output, ex)); /// /// Write the given user progress message to the log output @@ -351,21 +365,11 @@ namespace SabreTools.Logging /// Current count for progres /// String to be written log public static void User(object? instance, long total, long current, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.USER, output)); - } + => LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.USER, output)); - /// - /// Write the given exception as a warning to the log output - /// - /// Instance object that's the source of logging - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public static void Warning(object? instance, Exception ex, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.WARNING, output, ex)); - } + #endregion + + #region Warning /// /// Write the given string as a warning to the log output @@ -374,9 +378,26 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public static void Warning(object? instance, string output) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.WARNING, output, null)); - } + => LogEventHandler(instance, new LogEventArgs(LogLevel.WARNING, output)); + + /// + /// Write the given exception as a warning to the log output + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// True if the output could be written, false otherwise + public static void Warning(object? instance, Exception ex) + => LogEventHandler(instance, new LogEventArgs(LogLevel.WARNING, ex)); + + //// + /// Write the given exception and string as a warning to the log output + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public static void Warning(object? instance, Exception ex, string output) + => LogEventHandler(instance, new LogEventArgs(LogLevel.WARNING, output, ex)); /// /// Write the given warning progress message to the log output @@ -386,21 +407,11 @@ namespace SabreTools.Logging /// Current count for progres /// String to be written log public static void Warning(object? instance, long total, long current, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.WARNING, output)); - } + => LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.WARNING, output)); - /// - /// Writes the given exception as an error in the log - /// - /// Instance object that's the source of logging - /// Exception to be written log - /// String to be written log - /// True if the output could be written, false otherwise - public static void Error(object? instance, Exception ex, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.ERROR, output, ex)); - } + #endregion + + #region Error /// /// Writes the given string as an error in the log @@ -409,9 +420,26 @@ namespace SabreTools.Logging /// String to be written log /// True if the output could be written, false otherwise public static void Error(object? instance, string output) - { - LogEventHandler(instance, new LogEventArgs(LogLevel.ERROR, output, null)); - } + => LogEventHandler(instance, new LogEventArgs(LogLevel.ERROR, output)); + + /// + /// Writes the given exception as an error in the log + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// True if the output could be written, false otherwise + public static void Error(object? instance, Exception ex) + => LogEventHandler(instance, new LogEventArgs(LogLevel.ERROR, ex)); + + /// + /// Writes the given exception and string as an error in the log + /// + /// Instance object that's the source of logging + /// Exception to be written log + /// String to be written log + /// True if the output could be written, false otherwise + public static void Error(object? instance, Exception ex, string output) + => LogEventHandler(instance, new LogEventArgs(LogLevel.ERROR, output, ex)); /// /// Write the given error progress message to the log output @@ -421,9 +449,9 @@ namespace SabreTools.Logging /// Current count for progres /// String to be written log public static void Error(object? instance, long total, long current, string? output = null) - { - LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.ERROR, output)); - } + => LogEventHandler(instance, new LogEventArgs(total, current, LogLevel.ERROR, output)); + + #endregion #endregion }