We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Recently released Hangfire 1.6.3 includes injectable context object for jobs

When activated, job parameters of type PerformContext, now get replaced with the actual PerformContext of your job.

This allows a job like:

    public void Job(PerformContext context, IJobCancellationToken cancellationToken)
        string yourId = context.BackgroundJob.Id;
        //use this id to add state messages or other things


A simple example class (not mine) for using this id to log messages to the dashboard through SQL Server is:

Didn’t see it mentioned anywhere and happened to run across it while looking a the github diffs.

1 Like