diff --git a/Logging/LoggingHelper.cs b/Logging/LoggingHelper.cs index 98cf210e..a36a26fd 100644 --- a/Logging/LoggingHelper.cs +++ b/Logging/LoggingHelper.cs @@ -44,7 +44,7 @@ public static void AddErrorLog(this ILogReceiver receiver, Func getMessa /// /// Logs receiver. /// The level of the log message. - /// The function returns the text for . + /// The function that returns the text for . public static void AddLog(this ILogReceiver receiver, LogLevels level, Func getMessage) { if (receiver == null) @@ -58,7 +58,7 @@ public static void AddLog(this ILogReceiver receiver, LogLevels level, Func /// Logs receiver. /// Text message. - /// Text message settings. Used if a message is the format string. For details, see . + /// Text message settings. Used if the message is a format string. public static void AddInfoLog(this ILogReceiver receiver, string message, params object[] args) { receiver.AddMessage(LogLevels.Info, message, args); @@ -69,7 +69,7 @@ public static void AddInfoLog(this ILogReceiver receiver, string message, params /// /// Logs receiver. /// Text message. - /// Text message settings. Used if a message is the format string. For details, see . + /// Text message settings. Used if the message is a format string. public static void AddVerboseLog(this ILogReceiver receiver, string message, params object[] args) { receiver.AddMessage(LogLevels.Verbose, message, args); @@ -80,7 +80,7 @@ public static void AddVerboseLog(this ILogReceiver receiver, string message, par /// /// Logs receiver. /// Text message. - /// Text message settings. Used if a message is the format string. For details, see . + /// Text message settings. Used if the message is a format string. public static void AddDebugLog(this ILogReceiver receiver, string message, params object[] args) { receiver.AddMessage(LogLevels.Debug, message, args); @@ -91,7 +91,7 @@ public static void AddDebugLog(this ILogReceiver receiver, string message, param /// /// Logs receiver. /// Text message. - /// Text message settings. Used if a message is the format string. For details, see . + /// Text message settings. Used if the message is a format string. public static void AddWarningLog(this ILogReceiver receiver, string message, params object[] args) { receiver.AddMessage(LogLevels.Warning, message, args); @@ -146,7 +146,7 @@ public static void AddErrorLog(this ILogReceiver receiver, Exception exception, /// /// Logs receiver. /// Text message. - /// Text message settings. Used if a message is the format string. For details, see . + /// Text message settings. Used if the message is a format string. public static void AddErrorLog(this ILogReceiver receiver, string message, params object[] args) { receiver.AddMessage(LogLevels.Error, message, args); @@ -177,10 +177,11 @@ public static void LogError(this Exception error, string format = null) } /// - /// Get for the source. If the value is equal to , then parental source level is taken. + /// Get for the source. If the value is equal to , + /// then the parental source level is taken. /// /// The log source. - /// Logging level. + /// The logging level. public static LogLevels GetLogLevel(this ILogSource source) { if (source == null) @@ -201,9 +202,9 @@ public static LogLevels GetLogLevel(this ILogSource source) } /// - /// Wrap the specified action in try/catch clause with logging. + /// Wrap the specified action in a try/catch clause with logging. /// - /// The action. + /// The action to execute. public static void DoWithLog(this Action action) { if (action == null) @@ -220,11 +221,11 @@ public static void DoWithLog(this Action action) } /// - /// Wrap the specified action in try/catch clause with logging. + /// Wrap the specified function in a try/catch clause with logging. /// - /// The type of returned result. - /// The action. - /// The resulting value. + /// The type of the returned result. + /// The function to execute. + /// The resulting value, or the default value of T if an error occurs. public static T DoWithLog(this Func action) { if (action == null) @@ -242,11 +243,10 @@ public static T DoWithLog(this Func action) } /// - /// Wrap the specified action in try/catch clause with logging. + /// Executes the function that returns a dictionary, logs any exceptions, and logs a specific error for each key/value pair. /// - /// The type of returned result. - /// The action. - /// The resulting value. + /// The type of the dictionary key. + /// The function to execute that returns a dictionary. public static void DoWithLog(Func> action) { if (action == null) @@ -268,13 +268,14 @@ public static void DoWithLog(Func> action) } /// - /// Wrap the specified action in try/catch clause with logging. + /// Safely converts each element of an enumerable collection using a specified converter function. + /// Logs any exceptions that occur during conversion. /// - /// The type of source values. - /// The type of returned result. - /// Source values - /// Converter. - /// Result. + /// The type of the elements in the source enumerable. + /// The type of the elements in the resulting array. + /// The source enumerable. + /// The converter function. + /// An array containing the converted elements. public static T2[] SafeAdd(this IEnumerable from, Func func) { if (from == null) @@ -308,11 +309,11 @@ public static T2[] SafeAdd(this IEnumerable from, Func func) public static readonly Func OnlyError = message => message.Level == LogLevels.Error; /// - /// Filter messages. + /// Filters messages based on provided filters. /// - /// Incoming messages. - /// Messages filters that specify which messages should be handled. - /// Filtered collection. + /// The collection of messages to filter. + /// A collection of filter predicates to determine which messages to include. + /// An enumerable of filtered messages. public static IEnumerable Filter(this IEnumerable messages, ICollection> filters) { if (filters.Count > 0) @@ -322,13 +323,20 @@ public static IEnumerable Filter(this IEnumerable messag } /// - /// Write message. + /// Writes a single log message using the specified listener. /// - /// - /// + /// The log listener. + /// The log message to write. public static void WriteMessage(this ILogListener listener, LogMessage message) - => listener.CheckOnNull(nameof(message)).WriteMessages([message]); + => listener.CheckOnNull(nameof(message)).WriteMessages(new[] { message }); + /// + /// Continues the task, observing any errors and optionally executing the specified action. + /// + /// The task to observe. + /// An action to handle exceptions if the task faults. + /// An optional action to execute if the task completes successfully. + /// A new task representing the continuation. public static Task ObserveError(this Task task, Action observer, Action other = null) { if (task is null) throw new ArgumentNullException(nameof(task)); @@ -344,6 +352,14 @@ public static Task ObserveError(this Task task, Action observer, Acti }); } + /// + /// Continues the generic task, observing any errors and optionally executing the specified action. + /// + /// The type of the task result. + /// The task to observe. + /// An action to handle exceptions if the task faults. + /// An optional action to execute if the task completes successfully. + /// A new task representing the continuation. public static Task ObserveError(this Task task, Action observer, Action> other = null) { if (task is null) throw new ArgumentNullException(nameof(task)); @@ -359,9 +375,19 @@ public static Task ObserveError(this Task task, Action observer }); } + /// + /// Observes errors from the task and logs them. + /// + /// The task to observe. + /// A new task representing the continuation. public static Task ObserveErrorAndLog(this Task task) => task.ObserveError(ex => ex.LogError()); + /// + /// Observes errors from the task and traces them using . + /// + /// The task to observe. + /// A new task representing the continuation. public static Task ObserveErrorAndTrace(this Task task) => task.ObserveError(ex => Trace.WriteLine(ex)); } \ No newline at end of file diff --git a/common.props b/common.props index 6f289af9..1b4b0ef2 100644 --- a/common.props +++ b/common.props @@ -46,6 +46,8 @@ '$(MSBuildProjectName)' == 'Net.HPSocket' or '$(MSBuildProjectName)' == 'SmartFormat' or '$(MSBuildProjectName)' == 'StringSearch' or + '$(MSBuildProjectName)' == 'Interop' or + '$(MSBuildProjectName)' == 'Interop.Windows' or '$(MSBuildProjectName)' == 'Tests' "> false