Reputation: 8009
Is it possible to use ILog below with Azure Function logging or Serilog etc?
I cannot find code example on how to use it.
Rebus.Logging.ILog
.Options(o =>
{
o.Decorate<IErrorHandler>(c =>
new ErrorMessageHandler(c.Get<IErrorHandler>(), c.Get<ILog>()));
Upvotes: 0
Views: 585
Reputation: 18628
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
}
}
Upvotes: 0