Custom exceptions and custom error handling/logging?

Is there a way to implement custom error handling for (custom) exceptions and as a result setup logging as I want to?

I’m using Serilog for logging and Hangfire for re-occurring jobs which sometimes tend to fail, and to have as much information as possible I implemented custom exceptions for various types of possible fails.

I tried adding and registering a custom error handling middleware but I found out this middleware is not used when hangfire jobs are in question. Hangfire logs internally all the exceptions thrown after the job fails (after x retries). What I’m missing here is that although the exception is logged Hangfire doesn’t log all the custom fields I implemented in my custom exception.

I’m aware of Filters which can check the state of the job, and if state is failed I can the log it, but the problem there is that the exception is then passed further and logged once more by Hangfire.

Is there a better approach on how to handle Hangfire exceptions globally?