Ejemplo n.º 1
0
 private static void AddWellKnownFilters(this LogBuilder builder)
 {
     builder
     .AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning)
     .AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning)
     .AddFilter("Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", Microsoft.Extensions.Logging.LogLevel.Error);
 }
Ejemplo n.º 2
0
        public static IServiceCollection AddConsoleLykkeLogging([NotNull] this IServiceCollection services, [CanBeNull] Action <ILogBuilder> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton <IHealthNotifier>(s => EmptyHealthNotifier.Instance);

            services.AddSingleton <ILogFactory, LogFactory>(s => new LogFactory(
                                                                s.GetRequiredService <ILoggerFactory>(),
                                                                () => EmptyHealthNotifier.Instance,
                                                                s.GetService <IOptions <SanitizingOptions> >()));

            services.AddLogging();

            var builder = new LogBuilder(services);

            builder.AddWellKnownFilters();

            configure?.Invoke(builder);

            builder.AddConsole(builder.ConfigureConsole);

            return(services);
        }
Ejemplo n.º 3
0
        public static IServiceCollection AddLykkeLogging(
            [NotNull] this IServiceCollection services,
            [NotNull] IReloadingManager <string> azureTableConnectionString,
            [NotNull] string azureTableName,
            [NotNull] string slackAzureQueueConnectionString,
            [NotNull] string slackAzureQueuesBaseName,
            [CanBeNull] Action <ILogBuilder> configure = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (AppEnvironment.EnvInfo == null)
            {
                throw new InvalidOperationException("ENV_INFO environment should be not empty. If you run application in your local machine, please fill up ENV_INFO with your name.");
            }
            if (AppEnvironment.Name == null)
            {
                throw new InvalidOperationException("Application name should be not empty");
            }
            if (AppEnvironment.Version == null)
            {
                throw new InvalidOperationException("Application version should be not empty");
            }

            services.AddSingleton <IHealthNotifier, HealthNotifier>(s =>
            {
                var slackSenderFactory = new HealthNotifierSlackSenderFactory();

                return(new HealthNotifier(
                           slackSenderFactory.Create(slackAzureQueueConnectionString, slackAzureQueuesBaseName)));
            });

            services.AddSingleton <Func <IHealthNotifier> >(s => s.GetRequiredService <IHealthNotifier>);

            services.AddSingleton <ILogFactory, LogFactory>(s => new LogFactory(
                                                                s.GetRequiredService <ILoggerFactory>(),
                                                                s.GetRequiredService <Func <IHealthNotifier> >(),
                                                                s.GetService <IOptions <SanitizingOptions> >()));

            services.AddLogging();

            var builder = new LogBuilder(services);

            builder.AddWellKnownFilters();

            configure?.Invoke(builder);

            builder
            .AddConsole(builder.ConfigureConsole)
            .AddAzureTable(azureTableConnectionString, azureTableName, builder.ConfigureAzureTable)
            .AddEssentialSlackChannels(slackAzureQueueConnectionString, slackAzureQueuesBaseName, builder.ConfigureEssentialSlackChannels);

            return(services);
        }