How to get jobid within job?

General recommendation is to forget about Hangfire in your jobs (except IJobCancellationToken :frowning:). However, you can create a server filter for that:

public class JobContext : IServerFilter
{
    [ThreadStatic]
    private static string _jobId;

    public static string JobId { get { return _jobId; } set { _jobId = value; } }

    public void OnPerforming(PerformingContext context)
    {
        JobId = context.JobId;
    }
}

// And register it
GlobalConfiguration.Configuration.UseFilter(new JobContext());