/// <summary> /// Logs the and then ignores the exceptions thrown from the task if any. /// </summary> /// <param name="self">The task itself</param> /// <param name="logger">Logger to log against</param> /// <param name="msg">Optional message to be included</param> /// <param name="logLevel">Optional parameter to set log level</param> public static void LogAndIgnoreExceptionIfAny(this Task self, Logger logger, string msg = "", Level logLevel = Level.Error) { self.ContinueWith(t => { // ReSharper disable once PossibleNullReferenceException ; We know the task is Faulted logger.Log(logLevel, "{0} Exception:{1}", t.Exception.GetBaseException()); }, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); }