Beispiel #1
0
        /// <summary>
        /// Adds a Slack logger that logs entries to the additional Slack channel.
        /// </summary>
        /// <param name="factory">The <see cref="ILogBuilder"/> to use.</param>
        /// <param name="azureQueueConnectionString">Azure storage queue connection string</param>
        /// <param name="azureQueuesBaseName">Azure queue base name</param>
        /// <param name="channel">Channel ID</param>
        /// <param name="configure">Optional configuration action</param>
        public static ILogFactory AddAdditionalSlackChannel(
            [NotNull] this ILogFactory factory,
            [NotNull] string azureQueueConnectionString,
            [NotNull] string azureQueuesBaseName,
            [NotNull] string channel,
            [CanBeNull] Action <AdditionalSlackLoggerOptions> configure = null)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (string.IsNullOrWhiteSpace(azureQueueConnectionString))
            {
                throw new ArgumentNullException(nameof(azureQueueConnectionString));
            }
            if (string.IsNullOrWhiteSpace(azureQueuesBaseName))
            {
                throw new ArgumentNullException();
            }
            if (string.IsNullOrWhiteSpace(channel))
            {
                throw new ArgumentNullException(nameof(channel));
            }

            var spamGuard = SlackSpamGuardBuilder.BuildForAdditionalSlackChannel();
            var options   = new AdditionalSlackLoggerOptions(spamGuard);

            options.DisableChaosExceptionFiltering();

            configure?.Invoke(options);

            factory.AddProvider(new SlackLoggerProvider(
                                    azureQueueConnectionString,
                                    azureQueuesBaseName,
                                    spamGuard,
                                    SlackChannelResolvers.GetAdditionalChannelResolver(options.MinLogLevel, channel),
                                    options.FilterOutChaosException)
                                );

            return(factory);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a Slack logger that logs entries to the additional Slack channel.
        /// </summary>
        /// <param name="builder">The <see cref="ILogBuilder"/> to use.</param>
        /// <param name="channel">Channel ID</param>
        /// <param name="configure">Optional configuration action</param>
        public static ILogBuilder AddAdditionalSlackChannel(
            [NotNull] this ILogBuilder builder,
            [NotNull] string channel,
            [CanBeNull] Action <AdditionalSlackLoggerOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (string.IsNullOrWhiteSpace(channel))
            {
                throw new ArgumentNullException(nameof(channel));
            }

            var spamGuard = SlackSpamGuardBuilder.BuildForAdditionalSlackChannel();
            var options   = new AdditionalSlackLoggerOptions(spamGuard);

            options.DisableChaosExceptionFiltering();

            configure?.Invoke(options);

            builder.Services.AddSingleton <ILoggerProvider, SlackLoggerProvider>(s =>
            {
                var generalOptions = s.GetRequiredService <GeneralSlackLoggerOptions>();

                if (options.AreHealthNotificationsIncluded)
                {
                    var healthNotifier = (HealthNotifier)s.GetRequiredService <IHealthNotifier>();
                    healthNotifier.AddCustomSlackSender(channel);
                }

                return(new SlackLoggerProvider(
                           generalOptions.ConnectionString,
                           generalOptions.BaseQueuesName,
                           spamGuard,
                           SlackChannelResolvers.GetAdditionalChannelResolver(options.MinLogLevel, channel),
                           options.FilterOutChaosException));
            });

            return(builder);
        }