It's certainly possibly – but since Rebus' loggers are created with a type (the type works as a context of sorts – I think Serilog calls it "source context"), you do not inject the logger, you inject a logger factory:
.Options(o =>
{
o.Decorate<IErrorHandler>(c => {
var errorHandler = c.Get<IErrorHandler>();
var loggerFactory = c.Get<IRebusLoggerFactory>();
return new ErrorMessageHandler(errorHandler, loggerFactory));
});
}
and then, in the constructor of ErrorMessageHandler
, you can get the logger:
public class ErrorMessageHandler : IErrorHandler
{
readonly IErrorHandler errorHandler;
readonly ILog log;
public ErrorMessageHandler(IErrorHandler errorHandler, IRebusLoggerFactory loggerFactory)
{
this.errorHandler = errorHandler;
log = loggerFactory.GetLogger<ErrorMessageHandler>();
}
public async Task HandlePoisonMessage(TransportMessage transportMessage, ITransactionContext transactionContext, Exception exception)
{
// do stuff in here
}
}