/// <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); }
private IConnection CreateConnection() => _connectionFactory.GetConnectionFactory(_options.Connection.HostName, _options.Connection.VirtualHost, _options.Connection.Username, _options.Connection.Password).CreateConnection();