-
Notifications
You must be signed in to change notification settings - Fork 16
Logging
Microsoft.Extensions.Logging.Abstractions is used for the logging abstraction.
No logger is explicitly created; the queue uses the Null logger if nothing is set by the caller. If you want logging you need to inject your instance of ILoggerFactory as a singleton.
Here is a simple serilog example
var log = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Debug()
.CreateLogger();
Log.Logger = log;
//NOTE - Serilog requires that you configure and setup serilog before creating the logging factory
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddFilter(level => level >= LogLevel.Debug)
.AddSerilog();
}
);
//when obtaining a queuecontainer, register the logging factory
container.Register<ILoggerFactory>(() => loggerFactory, LifeStyles.Singleton);The integration tests uses a custom log provider to log errors - it can be found Here
When a message handler runs, MessageId and CorrelationId are automatically pushed into the ILogger scope. Any logging you do inside your handler carries these values with no extra configuration.
consumer.Start<MyMessage>((message, notification) =>
{
// Any ILogger calls here automatically include MessageId and CorrelationId
_logger.LogInformation("Processing order");
// In Serilog output: [13:45:02 INF] Processing order {MessageId=42, CorrelationId=abc-123}
}, notifications);This works with any structured logging provider (Serilog, NLog, etc.). You can query your log backend by message ID to see all logs for a specific message, no extra code needed.
Always on, no configuration required.
For any issues please use the GitHub issues