public void Process(LoggingEvent[] logs)
{
Stopwatch sw = Stopwatch.StartNew();
try
{
LogLog.Debug(typeof(RabbitMQAppender), string.Concat("publishing ", logs.Length, " logs"));
byte[] body = _messageBuilder.Build(logs);
using (IConnection connection = _connectionFactory.CreateConnection())
{
using (IModel model = connection.CreateModel())
{
IBasicProperties basicProperties = model.CreateBasicProperties();
basicProperties.ContentEncoding = _messageBuilder.ContentEncoding;
basicProperties.ContentType = _messageBuilder.ContentType;
basicProperties.DeliveryMode = 2;
model.BasicPublish(Exchange, RoutingKey, basicProperties, body);
}
}
}
catch (Exception e)
{
LogLog.Debug(typeof(RabbitMQAppender), "Exception comunicating with rabbitmq", e);
}
finally
{
LogLog.Debug(typeof(RabbitMQAppender), string.Concat("process completed, took ", sw.Elapsed));
}
}