Hi, we are trying to implement our own logging in Hangfire so that we can log uncaught exceptions. While our provide does seem to be being used, it’s not being called when we enqueue a background job that simply throws a new ApplicationException(). Any guidance on what we may be doing wrong?
public class MyHangfireLogProvider : ILogProvider
{
private readonly string _apiKey;
public MyHangfireLogProvider(string apiKey)
{
_apiKey = apiKey;
}
public ILog GetLogger(string name)
{
return new MyHangfireLog(_apiKey);
}
}
public class MyHangfireLog : ILog
{
private readonly string _apiKey;
public MyHangfireLog(string apiKey)
{
_apiKey = apiKey;
}
public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception = null)
{
if(exception != null)
{
var client = new RaygunClient(_apiKey);
client.Send(exception, null, null);
}
return true;
}
}
LogProvider.SetCurrentLogProvider(new MyHangfireLogProvider(ConfigurationService.RaygunConfiguration.ApiKey));