/// <summary> /// Extension for Task to execute the task in background and log any exception. /// </summary> /// <param name="task">Task to execute and capture any exceptions.</param> /// <param name="logger">Graph logger.</param> /// <param name="description">Friendly description of the task for debugging purposes.</param> /// <param name="memberName">Calling function.</param> /// <param name="filePath">File name where code is located.</param> /// <param name="lineNumber">Line number where code is located.</param> /// <returns> /// A <see cref="Task" /> representing the asynchronous operation. /// </returns> public static async Task ForgetAndLogExceptionAsync( this Task task, IGraphLogger logger, string description = null, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0) { try { await task.ConfigureAwait(false); logger?.Verbose( $"Completed running task successfully: {description ?? string.Empty}", memberName: memberName, filePath: filePath, lineNumber: lineNumber); } catch (Exception e) { // Log and absorb all exceptions here. logger?.Error( e, $"Caught an Exception running the task: {description ?? string.Empty}", memberName: memberName, filePath: filePath, lineNumber: lineNumber); } }