A Serilog sink that writes AMQP 1.0 messages using the AMQPNetLite package. Can be used as an alternative to serilog-sinks-azureeventhub and serilog-sinks-rabbitmq, enabling you to easily switch between message brokers, by changing the connection string.
The sink has been tested to work with EventHub and RabbitMQ.
The most basic minimalistic sink initialization is done like this.
namespace SerilogAMQPSinkTest
{
class Program
{
static void Main(string[] args)
{
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.AMQP(new AMQPSinkOptions()
{
ConnectionString = configuration["AMQPConnectionString"],
SenderLinkName = configuration["AMQPSenderLinkName"],
Entity = configuration["AMQPEntity"],
PeriodicBatchingSinkOptions = new PeriodicBatchingSinkOptions()
{
BatchSizeLimit = int.Parse(configuration["AMQPBatchSizeLimit"]),
QueueLimit = int.Parse(configuration["AMQPQueueLimit"]),
EagerlyEmitFirstEvent = bool.Parse(configuration["AMQPQEagerlyEmitFirstEvent"]),
Period = TimeSpan.FromSeconds(int.Parse(configuration["AMQPPeriod"]))
}
})
.CreateLogger();
Log.Logger.Information("Test");
}
}
}
Use the ConnectionString
property of AMQPSinkOptions
to specify the endpoint.
A free, hosted and managed RabbitMQ instance can be created at stackhero. Current sink has been tested with RabbitMQ and works following connection string format:
amqps://username:[email protected]:5671
The sink has also been tested with EventHub and works with the same format.
amqps://username:[email protected]:5671