Path: redb-route/redb.Route/Processors/LogProcessor.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Processors/LogProcessor.cs
----
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
namespace redb.Route.Processors;
///
/// Logs a message for each exchange passing through.
/// Supports static messages and dynamic expressions via Func.
///
public class LogProcessor : IProcessor
{
private readonly ILogger _logger;
private readonly Func _messageFunc;
private readonly LogLevel _level;
/// Creates a log processor with a static message.
/// Logger instance.
/// Static log message.
/// Log level (default: Information).
public LogProcessor(ILogger logger, string message, LogLevel level = LogLevel.Information)
: this(logger, _ => message, level)
{
}
/// Creates a log processor with a dynamic message function.
/// Logger instance.
/// Function to compute the log message from the exchange.
/// Log level (default: Information).
public LogProcessor(ILogger logger, Func messageFunc, LogLevel level = LogLevel.Information)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_messageFunc = messageFunc ?? throw new ArgumentNullException(nameof(messageFunc));
_level = level;
}
///
public Task Process(IExchange exchange, CancellationToken ct = default)
{
#pragma warning disable CA2254 // Template should be a static expression
_logger.Log(_level, "{Message}", _messageFunc(exchange));
#pragma warning restore CA2254
return Task.CompletedTask;
}
}