/// <summary> /// Creates an instance of <c>TacitusLogger.Destinations.RabbitMq.RabbitMqDestination</c> using all its dependencies. /// </summary> /// <param name="rabbitMqConnection">RabbitMQ connection that will be used to publish messages.</param> /// <param name="messagePublisher">An implementation of <c>TacitusLogger.Destinations.RabbitMq.Publishers.IMessagePublisher</c> that encapsulates the publishing logic.</param> /// <param name="publicationAddressProvider">An implementation of <c>TacitusLogger.Destinations.RabbitMq.PublicationAddressProviders.IPublicationAddressProvider</c> that provides the publication address.</param> /// <param name="logSerializer">Log model serializer.</param> public RabbitMqDestination(IConnection rabbitMqConnection, IPublicationAddressProvider publicationAddressProvider, ILogSerializer logSerializer, IMessagePublisher messagePublisher) { _rabbitMqConnection = rabbitMqConnection ?? throw new ArgumentNullException("rabbitMqConnection"); _messagePublisher = messagePublisher ?? throw new ArgumentNullException("messagePublisher"); _publicationAddressProvider = publicationAddressProvider ?? throw new ArgumentNullException("publicationAddressProvider"); _logSerializer = logSerializer ?? throw new ArgumentNullException("logSerializer"); }
/// <summary> /// Completes log destination build process by adding it to the parent log group destination builder. /// </summary> /// <returns></returns> public ILogGroupDestinationsBuilder Add() { // Mandatory dependencies. if (_rabbitMqConnection == null) { throw new InvalidOperationException("RabbitMQ connection was not specified during the build"); } if (_publicationAddressProvider == null) { throw new InvalidOperationException("Publication address provider was not specified during the build"); } // Dependencies with defaults. if (_messagePublisher == null) { _messagePublisher = new BasicMessagePublisher(); } if (_logSerializer == null) { _logSerializer = new JsonLogSerializer(); } // Create the destination. RabbitMqDestination rabbitMqDestination = new RabbitMqDestination(_rabbitMqConnection, _publicationAddressProvider, _logSerializer, _messagePublisher); // Add to log group and return it. return(_logGroupDestinationsBuilder.CustomDestination(rabbitMqDestination)); }
/// <summary> /// Adds the log data serializer of type <c>TacitusLogger.Serializers.ILogSerializer</c> that is used to generate /// RabbitMQ message strings of specific format and content. /// </summary> /// <param name="logSerializer">The log data serializer.</param> /// <returns>Self.</returns> public IRabbitMqDestinationBuilder WithLogSerializer(ILogSerializer logSerializer) { if (_logSerializer != null) { throw new InvalidOperationException("Log data serializer has already been set during this build"); } _logSerializer = logSerializer ?? throw new ArgumentNullException("logSerializer"); return(this); }
/// <summary> /// Creates an instance of <c>TacitusLogger.Destinations.RabbitMq.RabbitMqDestination</c> using /// <c>TacitusLogger.Destinations.RabbitMq.Publishers.BasicMessagePublisher</c> as a default message publisher /// and <c>TacitusLogger.Destinations.RabbitMq.PublicationAddressProviders.DirectPublicationAddressProvider</c> as a /// default publication address provider. /// </summary> /// <param name="rabbitMqConnection"></param> /// <param name="logSerializer"></param> /// <param name="exchangeName"></param> /// <param name="exchangeType"></param> /// <param name="routingKey"></param> public RabbitMqDestination(IConnection rabbitMqConnection, ILogSerializer logSerializer, string exchangeName, string exchangeType, string routingKey = "") : this(rabbitMqConnection, new DirectPublicationAddressProvider(exchangeName, exchangeType, routingKey), logSerializer, new BasicMessagePublisher()) { }
/// <summary> /// Creates an instance of <c>TacitusLogger.Destinations.RabbitMq.RabbitMqDestination</c> using /// <c>TacitusLogger.Destinations.RabbitMq.Publishers.BasicMessagePublisher</c> as a default message publisher. /// </summary> /// <param name="rabbitMqConnection"></param> /// <param name="publicationAddressProvider"></param> /// <param name="logSerializer"></param> public RabbitMqDestination(IConnection rabbitMqConnection, IPublicationAddressProvider publicationAddressProvider, ILogSerializer logSerializer) : this(rabbitMqConnection, publicationAddressProvider, logSerializer, new BasicMessagePublisher()) { }
public ILogFactory AddSerializer(ILogSerializer serializer) { Ensure.NotNull(serializer, "serializer"); serializers.Add(serializer); return(this); }