/// <summary> /// Adds the RabbitMQ sink to serilog /// </summary> /// <param name="configuration">Serilog Sink Configuration.</param> /// <param name="rabbitConnectionFactory">The <see cref="IRabbitConnectionFactory" /> to use when creating the connection to RabbitMQ.</param> /// <param name="rabbitMessageBuilder">The <see cref="IRabbitMessageBuilder" /> to use when sending messages to RabbitMQ.</param> /// <param name="batchSizeLimit">Maximum locally queued message count before sending to RabbitMQ.</param> /// <param name="batchSubmitTimeSeconds">Maximum time to allow locally queued messages to be queued before sending to RabbitMQ.</param> /// <param name="textFormatter">The ITextFormatter to use when formatting the message. If null, this will default to the built-in Serilog JsonFormatter.</param> /// <param name="formatProvider">The IFormatProvider to use when formatting the message. If null, this will default to the standard .NET format provider.</param> /// <returns></returns> public static LoggerConfiguration RabbitMQ(this LoggerSinkConfiguration configuration, IRabbitConnectionFactory rabbitConnectionFactory, IRabbitMessageBuilder rabbitMessageBuilder, int batchSizeLimit = 50, int batchSubmitTimeSeconds = 2, ITextFormatter textFormatter = null, IFormatProvider formatProvider = null) { var sink = new RabbitMQSink(batchSizeLimit, TimeSpan.FromSeconds(batchSubmitTimeSeconds), textFormatter, formatProvider, rabbitConnectionFactory, rabbitMessageBuilder); return(configuration.Sink(sink)); }
/// <summary> /// The Serilog sink that will send log messages to a RabbitMQ server /// </summary> /// <param name="batchSizeLimit">Maximum locally queued message count before sending to RabbitMQ.</param> /// <param name="batchSubmitTimeSeconds">Maximum time to allow locally queued messages to be queued before sending to RabbitMQ.</param> /// <param name="textFormatter">The ITextFormatter to use when formatting the message. If null, this will default to the built-in Serilog JsonFormatter.</param> /// <param name="formatProvider">The IFormatProvider to use when formatting the message. If null, this will default to the standard .NET format provider.</param> /// <param name="rabbitConnectionFactory">The <see cref="IRabbitConnectionFactory" /> to use when creating the connection to RabbitMQ.</param> /// <param name="rabbitMessageBuilder">The <see cref="IRabbitMessageBuilder" /> to use when sending messages to RabbitMQ.</param> public RabbitMQSink(int batchSizeLimit, TimeSpan batchSubmitTimeSeconds, ITextFormatter textFormatter, IFormatProvider formatProvider, IRabbitConnectionFactory rabbitConnectionFactory, IRabbitMessageBuilder rabbitMessageBuilder) : base(batchSizeLimit, batchSubmitTimeSeconds) { _formatProvider = formatProvider; _textFormatter = textFormatter ?? new JsonFormatter(renderMessage: true); _connectionFactory = rabbitConnectionFactory.GetConnectionFactory(); _rabbitMessageBuilder = rabbitMessageBuilder; _connection = _connectionFactory.CreateConnection(); _model = _connection.CreateModel(); _basicProperties = _model.CreateBasicProperties(); rabbitConnectionFactory.ConfigureBasicProperties(_basicProperties); }