Repository navigation
Logging
DotNetWorkQueue uses Microsoft.Extensions.Logging.Abstractions for the logging abstraction.
The queue does not create a logger explicitly. If the caller does not set a logger, the queue uses the Null logger. 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 use a custom log provider to log errors. You can find it Here
When a message handler runs, the consumer automatically pushes MessageId and CorrelationId 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. You do not need extra code for this.
The logging scope is always on and needs no configuration.
For any issues please use the GitHub issues