I have a logging issue with Serilog 2.3 inside hangfire 1.6.8.
I have a enqueued hangfire job that uses serilog to log and after some random number of jobs it will stop logging. I will re-queue those jobs and it will randomly stop logging on a different job that previously logged. When it does fail its at random points.
I have a scheduled job using serilog that logs just fine.
There are no errors in the hangfire log which is using nlog.
The jobs continue to run and the results are correct.
I'm using the appsettingsconfig sink.
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings(settingPrefix: "MyJob")
.CreateLogger();
I have no idea what to do or where to look.
I think hangfire creates the object and every time a job is called it calls a method on my object. Is there some odd async issue i need to handle with serilog?
Please help!
I have created a new job that only logs and it has the exact same behavior.
public class Logging
{
public Logging()
{
// Configure logging sinks
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings(settingPrefix: "LoggingTest")
.CreateLogger().ForContext<Logging>();
}
public void LogSomething(string something)
{
Log.Information("Log: {0}", something);
}
}
DOH! I see now that its some sort of static issue with Serilog. With it being static, hangfire reuses objects (my ioc) and each job is logging to each others files because it all runs under hangfires app domain, so its not really stopping the log as much as the enqueued jobs run until the scheduled job runs a minute later and moves the file location and then both the enqueued and scheduled job log to the path defined for the scheduled job.