# Hangfire Failure Alerts in Slack and Email

By Dan Ochoa · Published 2026-11-21 · Updated 2026-11-21
Canonical: https://cronradar.com/blog/hangfire-failure-alerts-slack-email

> Hangfire has no built-in failure alerts. See how a job filter and a Slack webhook work, where retries and missed runs break them, and how to alert from outside.

**Hangfire doesn't send failure alerts on its own: its dashboard shows failed jobs, but nobody hears about them unless they look.** You can add alerts two ways. Write a job filter that posts to a Slack incoming webhook or sends an email when a job reaches the Failed state, or monitor the jobs from outside the Hangfire process. A filter is a few dozen lines, but it alerts only after Hangfire's retries run out, more than four hours later at the defaults, and it can't see a job that never ran or one that hangs. An outside monitor that knows each job's schedule catches all three.

This guide covers Hangfire 1.8.

## The Do-It-Yourself Version: A Filter and a Slack Webhook

Hangfire decides a job's next state in two phases. Election filters, including the built-in `AutomaticRetry`, can still replace a Failed candidate with a scheduled retry. Apply filters run afterwards, with the state that is actually stored, so an applied `FailedState` means Hangfire has stopped retrying. [Hangfire automatic retry](https://cronradar.com/blog/hangfire-automatic-retry#detect-the-final-failure-with-a-job-filter) explains the two phases in detail.

The filter runs inside Hangfire's state-change transaction, so it should hand the failure off rather than call Slack itself. Here it writes to an in-process channel that a background service drains:

```csharp
using System.Net.Http.Json;
using System.Threading.Channels;
using Hangfire.States;
using Hangfire.Storage;

public sealed record JobFailure(string JobId, string? RecurringJobId, string ExceptionType);

public sealed class SlackFailureFilter : IApplyStateFilter
{
    private readonly ChannelWriter<JobFailure> _failures;

    public SlackFailureFilter(ChannelWriter<JobFailure> failures) => _failures = failures;

    public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
    {
        // Retryable failures were already turned into scheduled retries.
        if (context.NewState is not FailedState failed) return;

        _failures.TryWrite(new JobFailure(
            context.BackgroundJob.Id,
            context.GetJobParameter<string>("RecurringJobId", allowStale: true),
            failed.Exception.GetType().Name));
    }

    public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
    {
    }
}

public sealed class SlackFailureSender(
    Channel<JobFailure> failures,
    IHttpClientFactory httpClients,
    IConfiguration configuration) : BackgroundService
{
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        var client = httpClients.CreateClient();
        var webhookUrl = configuration["Slack:WebhookUrl"];

        await foreach (var failure in failures.Reader.ReadAllAsync(stoppingToken))
        {
            var text = $"Hangfire job {failure.RecurringJobId ?? failure.JobId} failed: {failure.ExceptionType}";
            try
            {
                await client.PostAsJsonAsync(webhookUrl, new { text }, stoppingToken);
            }
            catch (HttpRequestException)
            {
                // Slack was unreachable; this alert is lost.
            }
        }
    }
}
```

Register the channel, the sender and the filter once:

```csharp
using System.Threading.Channels;
using Hangfire;

var failures = Channel.CreateUnbounded<JobFailure>();
builder.Services.AddSingleton(failures);
builder.Services.AddHttpClient();
builder.Services.AddHostedService<SlackFailureSender>();

builder.Services.AddHangfire(config => config
    .UseSqlServerStorage(builder.Configuration.GetConnectionString("Hangfire"))
    .UseFilter(new SlackFailureFilter(failures.Writer)));
builder.Services.AddHangfireServer();
```

A Slack incoming webhook accepts a JSON body with a `text` field. For email, replace the sender's HTTP call with your SMTP client or email provider; the filter stays the same.

## Where the Filter Falls Short

The filter answers one question, "did a job end in Failed?", and only while the process that runs Hangfire is healthy.

| What happened                                   | What the filter does                                                   |
| ----------------------------------------------- | ---------------------------------------------------------------------- |
| A job throws and Hangfire retries it            | Nothing until the last retry fails: 4 h 18 min or more at the defaults |
| A job fails once, then succeeds on retry        | Nothing, which is usually what you want                                |
| The server stops, or the app pool is recycled   | Nothing: no job runs, so no state changes                              |
| A deploy removes a recurring job's registration | Nothing: the job is simply gone                                        |
| A job hangs in Processing                       | Nothing: it never reaches Failed                                       |
| The host crashes with failures still queued     | The in-memory channel is lost, and those alerts with it                |

**The retry problem.** Hangfire retries a failed job 10 times by default, with delays that grow to almost two hours, so the final Failed state arrives hours after the first error. Hooking an earlier phase instead, such as a server filter's `OnPerformed`, alerts on every failed attempt, including the ones a retry fixes. Neither is right for every job: shorten the retry chain on jobs where a late alert is useless. [Hangfire automatic retry](https://cronradar.com/blog/hangfire-automatic-retry) has the delay formula and the settings.

**Nothing fails when nothing runs.** The most expensive Hangfire incidents are the quiet ones: a stopped server, a sleeping web app, or a recurring job dropped by a deploy. Each produces no state change, so a filter has nothing to report. [Hangfire recurring job not running](https://cronradar.com/blog/hangfire-recurring-job-not-running) and [Hangfire jobs missing after deploy](https://cronradar.com/blog/hangfire-jobs-missing-after-deploy) cover the causes.

**Stuck jobs never fail.** A job blocked on I/O or a lock stays in Processing; [Hangfire job stuck processing](https://cronradar.com/blog/hangfire-job-stuck-processing) covers why. To alert on it you need to know how long the job should take, which the filter doesn't.

**The alert runs where the failure is.** If the host is down, its alerting is down too. Catching all of these needs something outside the process that knows each job's schedule and notices when the expected run doesn't report.

## Alert From Outside With AddCronRadarHangfire()

CronRadar is a hosted, cron-only monitoring service, and its Hangfire package is that outside check. It reads Hangfire's recurring-job registry, so it already knows every job and its schedule, and you don't create anything per job.

```bash
dotnet add package CronRadar.Hangfire
```

Call `AddCronRadarHangfire()` after `AddHangfire()`, and set `CRONRADAR_API_KEY` in the deployed process:

```csharp
using CronRadar.Hangfire;

builder.Services.AddHangfire(config =>
    config.UseSqlServerStorage(builder.Configuration.GetConnectionString("Hangfire")));
builder.Services.AddHangfireServer();

builder.Services.AddCronRadarHangfire();
```

At startup the package declares each recurring job and its cron schedule to CronRadar, then reconciles the registry every 15 minutes by default. A global Hangfire server filter reports start, completion and failure for every run. That covers each gap above:

- **Failures after retries.** A failure is reported only when Hangfire reaches its final Failed state, so intermediate attempts don't alert. Each report carries the background-job ID and retry count.
- **Runs that never happen.** CronRadar expects each run from the schedule. When none reports by the scheduled time plus the grace period, it sends a missed-run alert, whether the server stopped or the job was never picked up.
- **Stuck runs.** A run that starts and doesn't finish before the next one is due, plus grace, is alerted as stuck.
- **Jobs that vanish.** A recurring job missing from a later registry sync is reported and paused, with its history kept.

Alerts go to email, Slack, webhook, Discord or PagerDuty, and every plan includes all of them. You choose the channels in the console; the [alert channels guide](https://docs.cronradar.com/alert-channels) covers setup. Monitoring failures are caught, and every request to CronRadar times out after five seconds, so the package can't fail or stall a job. To leave one job out, put `[SkipMonitor]` on its method.

Keep the Hangfire dashboard for queues, retries and job administration. To try it on one application, the [Hangfire integration guide](https://docs.cronradar.com/integrations/hangfire) has the full setup and a verification checklist, and [Hangfire monitoring with CronRadar](https://cronradar.com/hangfire) has the overview.

## Frequently Asked Questions

### Can Hangfire send an email when a job fails?

Not on its own. Hangfire records the failure in storage and shows it on the dashboard's Failed page. To get an email, add an `IApplyStateFilter` that acts on an applied `FailedState` and hands the failure to your email sender, or use a monitor that sends email alerts for you.

### How do I send Hangfire job failures to Slack?

Create a Slack incoming webhook, then post a JSON message with a `text` field when a job reaches Failed, from a filter like the one above. Send it from a background service rather than inside the filter, because the filter runs during Hangfire's state change. CronRadar's Hangfire package does this without code, and also alerts on runs that never happen.

### Why does my Hangfire failure alert arrive hours late?

Because the job was retrying. An alert on the Failed state fires only after the last retry, and Hangfire's 10 default retries take over four hours. Lower `Attempts` or set `DelaysInSeconds` on jobs where you need to know sooner.

### Will a Hangfire filter tell me when a recurring job stops running?

No. A filter runs when a job changes state, and a job that never runs doesn't change state. Detecting a missed run needs something that knows the schedule and runs outside the Hangfire server.
