Exemplo n.º 1
0
        /// <summary>
        /// Adds a Slack logger that logs to the essential Slack channels
        /// </summary>
        /// <param name="factory">The <see cref="ILogFactory"/> to use.</param>
        /// <param name="azureQueueConnectionString">Azure storage queue connection string</param>
        /// <param name="azureQueuesBaseName">Azure queue base name</param>
        /// <param name="configure">Optional configuration</param>
        public static ILogFactory AddEssentialSlackChannels(
            [NotNull] this ILogFactory factory,
            [NotNull] string azureQueueConnectionString,
            [NotNull] string azureQueuesBaseName,
            Action <SlackLoggerOptions> 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();
            }

            var spamGuard = SlackSpamGuardBuilder.BuildForEssentialSlackChannelsSpamGuard();
            var options   = new SlackLoggerOptions(spamGuard);

            configure?.Invoke(options);

            factory.AddProvider(new SlackLoggerProvider(
                                    azureQueueConnectionString,
                                    azureQueuesBaseName,
                                    spamGuard,
                                    SlackChannelResolvers.EssentialChannelsResolver,
                                    options.FilterOutChaosException));

            return(factory);
        }
Exemplo n.º 2
0
        internal static ILogBuilder AddEssentialSlackChannels(
            [NotNull] this ILogBuilder builder,
            [NotNull] string azureQueueConnectionString,
            [NotNull] string azureQueuesBaseName,
            [CanBeNull] Action <SlackLoggerOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (string.IsNullOrWhiteSpace(azureQueueConnectionString))
            {
                throw new ArgumentNullException(nameof(azureQueueConnectionString));
            }
            if (string.IsNullOrWhiteSpace(azureQueuesBaseName))
            {
                throw new ArgumentNullException();
            }

            var spamGuard = SlackSpamGuardBuilder.BuildForEssentialSlackChannelsSpamGuard();
            var options   = new SlackLoggerOptions(spamGuard);

            configure?.Invoke(options);

            // This will be used by additional Slack channel loggers
            var generalOptions = new GeneralSlackLoggerOptions(azureQueueConnectionString, azureQueuesBaseName);

            builder.Services.AddSingleton(generalOptions);

            builder.Services.AddSingleton <ILoggerProvider, SlackLoggerProvider>(s => new SlackLoggerProvider(
                                                                                     azureQueueConnectionString,
                                                                                     azureQueuesBaseName,
                                                                                     spamGuard,
                                                                                     SlackChannelResolvers.EssentialChannelsResolver,
                                                                                     options.FilterOutChaosException));

            return(builder);
        }