1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Common/TPL/TaskExtensions.cs

25 lines
698 B
C#
Raw Normal View History

2013-07-12 09:10:34 +03:00
using System.Threading.Tasks;
using NLog;
namespace NzbDrone.Common.TPL
{
public static class TaskExtensions
{
private static readonly Logger Logger = LogManager.GetLogger("TaskExtensions");
public static Task LogExceptions(this Task task)
{
task.ContinueWith(t =>
{
var aggregateException = t.Exception.Flatten();
foreach (var exception in aggregateException.InnerExceptions)
{
Logger.ErrorException("Task Error", exception);
}
}, TaskContinuationOptions.OnlyOnFaulted);
return task;
}
}
}