Skip to content

Commit 7b66e47

Browse files
committed
Pass ILog instance to task scheduler's exception handler
1 parent 7871154 commit 7b66e47

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/Hangfire.Core/Server/BackgroundProcessDispatcherBuilderAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ internal sealed class BackgroundProcessDispatcherBuilderAsync : IBackgroundProce
2626
{
2727
private readonly int _maxConcurrency;
2828
private readonly bool _ownsScheduler;
29-
private readonly Func<TaskScheduler> _taskScheduler;
29+
private readonly Func<ILog, TaskScheduler> _taskScheduler;
3030
private readonly IBackgroundProcessAsync _process;
3131

3232
public BackgroundProcessDispatcherBuilderAsync(
3333
[NotNull] IBackgroundProcessAsync process,
34-
[NotNull] Func<TaskScheduler> taskScheduler,
34+
[NotNull] Func<ILog, TaskScheduler> taskScheduler,
3535
int maxConcurrency,
3636
bool ownsScheduler)
3737
{
@@ -66,7 +66,7 @@ public IBackgroundDispatcher Create(BackgroundServerContext context, BackgroundP
6666
processLogger,
6767
ExecuteProcess,
6868
Tuple.Create(_process, context, execution, processLogger),
69-
_taskScheduler(),
69+
_taskScheduler(processLogger),
7070
_maxConcurrency,
7171
_ownsScheduler);
7272
}

src/Hangfire.Core/Server/BackgroundProcessExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public static IBackgroundProcessDispatcherBuilder UseBackgroundPool(
103103
if (maxConcurrency <= 0) throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
104104
if (threadFactory == null) throw new ArgumentNullException(nameof(threadFactory));
105105

106-
Func<TaskScheduler> createScheduler = () => new BackgroundTaskScheduler(
106+
Func<ILog, TaskScheduler> createScheduler = logger => new BackgroundTaskScheduler(
107107
threadStart => threadFactory(process.GetType().Name, threadStart),
108-
static exception =>
108+
exception =>
109109
{
110-
LogProvider.GetLogger(typeof(BackgroundTaskScheduler)).FatalException(
111-
"Unhandled exception occurred in scheduler. Please report it to Hangfire developers",
110+
logger.FatalException(
111+
$"Unhandled exception occurred in `{nameof(BackgroundTaskScheduler)}`. Please report this to Hangfire developers.",
112112
exception);
113113
});
114114

@@ -128,7 +128,7 @@ public static IBackgroundProcessDispatcherBuilder UseThreadPool(
128128
if (process == null) throw new ArgumentNullException(nameof(process));
129129
if (maxConcurrency <= 0) throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
130130

131-
return new BackgroundProcessDispatcherBuilderAsync(process, static () => TaskScheduler.Default, maxConcurrency, false);
131+
return new BackgroundProcessDispatcherBuilderAsync(process, static _ => TaskScheduler.Default, maxConcurrency, false);
132132
}
133133

134134
internal static IEnumerable<Thread> DefaultThreadFactory(

0 commit comments

Comments
 (0)