コード例 #1
0
        /// <summary>
        /// Adds a sink that lets you push log messages to RabbitMQ
        /// Will be used when configuring via configuration file
        /// Is for backward-compatibility with previous version but gives possibility to use multiple hosts
        /// </summary>
        public static LoggerConfiguration RabbitMq(
            this LoggerSinkConfiguration loggerConfiguration,
            string mqHostName, string mqUserName, string mqPassword, string brokerName, Base.EventBus.ExchangeType exchangeType,
            bool exchangeDurable  = false, bool exchangeAutoDelete = false,
            bool queueDurable     = false, bool queueExclusive     = false, bool queueAutoDelete           = false,
            int batchPostingLimit = 0, TimeSpan period             = default, ITextFormatter textFormatter = null
            )
        {
            //RabbitMqClientConfiguration clientConfiguration = new RabbitMqClientConfiguration
            //{
            //    Username = username,
            //    Password = password,
            //    Exchange = exchange,
            //    ExchangeType = exchangeType,
            //    DeliveryMode = deliveryMode,
            //    RouteKey = routeKey,
            //    Port = port,
            //    VHost = vHost,
            //    Heartbeat = heartbeat,
            //    Protocol = protocol
            //};
            //foreach (string hostname in hostnames)
            //{
            //    clientConfiguration.Hostnames.Add(hostname);
            //}

            IConnectionFactory connectionFactory = new ConnectionFactory
            {
                HostName = mqHostName,
                UserName = mqUserName,
                Password = mqPassword,
                AutomaticRecoveryEnabled = true,
                NetworkRecoveryInterval  = TimeSpan.FromSeconds(10),
                RequestedHeartbeat       = TimeSpan.FromSeconds(10),
                DispatchConsumersAsync   = true
            };

            IExchangeDeclareParameters exchangeDeclareParameters = new ExchangeDeclareParameters(brokerName, exchangeType, exchangeDurable, exchangeAutoDelete);
            IQueueDeclareParameters    queueDeclareParameters    = new QueueDeclareParameters(queueDurable, queueExclusive, queueAutoDelete);

            RabbitMqSinkConfiguration sinkConfiguration = new RabbitMqSinkConfiguration
            {
                BatchPostingLimit = batchPostingLimit,
                Period            = period,
                TextFormatter     = textFormatter
            };

            return(RegisterSink(loggerConfiguration, connectionFactory, exchangeDeclareParameters, queueDeclareParameters, sinkConfiguration));
        }
コード例 #2
0
 /// <summary>
 /// Adds a sink that lets you push log messages to RabbitMQ
 /// Will be used when configuring via configuration file
 /// Is for backward-compatibility with previous version
 /// </summary>
 public static LoggerConfiguration RabbitMq(
     this LoggerSinkConfiguration loggerConfiguration,
     string mqHostName, string mqUserName, string mqPassword, string brokerName, Base.EventBus.ExchangeType exchangeType,
     bool exchangeDurable  = false, bool exchangeAutoDelete = false,
     bool queueDurable     = false, bool queueExclusive     = false, bool queueAutoDelete = false,
     int batchPostingLimit = 0,
     TimeSpan period       = default, ITextFormatter formatter = null, IFormatProvider formatProvider = null
     )
 {
     return(loggerConfiguration.RabbitMq(mqHostName, mqUserName, mqPassword,
                                         brokerName, exchangeType, exchangeDurable, exchangeAutoDelete,
                                         queueDurable, queueExclusive, queueAutoDelete,
                                         batchPostingLimit, period, formatter));
 }