As per the hangfire documentation
Starting from Hangfire 1.3.0, you are not required to do anything, if your application already uses one of the following libraries through the reflection (so that Hangfire itself does not depend on any of them). Logging implementation is automatically chosen by checking for the presence of corresponding types in the order shown below.
Serilog
NLog
Log4Net
EntLib
Logging
Loupe
Elmah
I have ASP.NET Core 2.0 application that is using Serilog
like below
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseApplicationInsights()
.UseUrls("http://*:40006")
.ConfigureAppConfiguration((hostingContext, config) =>
{
// removed for bravity
})
.ConfigureLogging((hostingContext, logging) =>
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(hostingContext.Configuration)
.CreateLogger();
logging.AddSerilog();
})
.Build();
}
The application is configured to use Hangfire. During background job processing if there is any exception occurs, Hangfire re-tries the job 10 times with increasing delay as expected, and it shows the exceptions in dashboard.
Issue
The Hangfire dashboard shows the exception on UI however it does not log the exception into configured Serilog sink.
Note: The Hangfire dashboard shows exception but it formats the exception see here which hides critical information about the exception. I think if it logs the exception, Serilog logger would log the complete exception.