Upgraded the Serilog package to fix the issue with the missing RawFormatter
.
Failure sink(s) can be configured through appsettings.json or via code.
In this example the Console sink is used as a failure sink. If the RabbitMQ sink fails to emit an event, it will write to the Console sink.
"Serilog": {
"Using": [ "Serilog.Sinks.RabbitMQ", "Serilog.Sinks.Console" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "RabbitMQ",
"Args": {
"username": "serilog",
"password": "serilog",
"hostnames": [
"localhost"
],
"emitEventFailure": "WriteToSelfLog,WriteToFailureSink",
"failureSinkConfiguration": [
{
"Name": "Console"
}
]
}
}
]
}
The SSL support has been improved. Now all properties are used when creating the connection.
- Renamed
LoggerConfigurationRabbitMqExtension
toLoggerConfigurationRabbitMQExtensions
. - Renamed
hostname
tohostnames
in configuration. - Default text formatter is
CompactJsonFormatter
. TheRawFromatter
was removed from Serilog. - Requires
Serilog.Sinks.PeriodicBatching
4.0
. This could break other sinks that inherit fromPeriodicBatchingSink
from this package. This was obsolete code and it has been removed. See release notes for more information.
Add support for RabbitMQ.Client
version 7.0.0
. Note that this is a breaking change. The RabbitMQ.Client
7.0.0
is not compatible with the RabbitMQ.Client
6.x
.
Removed reference to Serilog.Sinks.PeriodicBatching
and use Serilog.Sinks.Batch
instead.
Add support for setting BasicProperties
before publishing a message. Properties can be set by creating a class implementing ISendMessageEvents
.
public void OnSetMessageProperties(LogEvent logEvent, IBasicProperties properties)
{
// example of setting message headers based on log event properties
logEvent.Properties.TryGetValue("messageType", out var messageType);
properties.Headers = new Dictionary<string, object?>
{
{ "messageType", messageType?.ToString() },
};
// example of setting correlation id based on log event properties
if (logEvent.Properties.TryGetValue(LogProperties.CORRELATION_ID, out var correlationId))
{
properties.CorrelationId = correlationId.ToString();
}
}
Moved the logic for determining the routing key logic to the ISendMessageEvents
. This allows for more flexibility when setting the routing key.
public string OnGetRoutingKey(LogEvent logEvent, string defaultRoutingKey)
{
// example of routing based on log level
return logEvent.Level switch
{
LogEventLevel.Error => "error",
_ => _defaultRoutingKey
};
}
Add .net 9 to the target frameworks
- Upgrade RabbitMQ.Client to
7.0.0
. - Upgrade Serilog to
4.2.0
. - Renamed
Period
toBufferingTimeLimit
. - Renamed
RouteKey
toRoutingKey
- Removed
RoutingFunc
- Removed
.net7.0
target framework