mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-27 04:21:27 +02:00
added exception logging to Tasks.
This commit is contained in:
25
NzbDrone.Common/TPL/TaskExtensions.cs
Normal file
25
NzbDrone.Common/TPL/TaskExtensions.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user