Ejemplo n.º 1
0
        private static void AddServices(this IServiceCollection services, IConfiguration config)
        {
            services.Configure <RequestLogOptions>(
                config.GetSection("logging"));

            services.Configure <RequestLogStoreOptions>(
                config.GetSection("logging"));

            services.Configure <SemanticLogOptions>(
                config.GetSection("logging"));

            if (config.GetValue <bool>("logging:human"))
            {
                services.AddSingletonAs(_ => JsonLogWriterFactory.Readable())
                .As <IObjectWriterFactory>();
            }
            else
            {
                services.AddSingletonAs(_ => JsonLogWriterFactory.Default())
                .As <IObjectWriterFactory>();
            }

            var loggingFile = config.GetValue <string>("logging:file");

            if (!string.IsNullOrWhiteSpace(loggingFile))
            {
                services.AddSingletonAs(_ => new FileChannel(loggingFile))
                .As <ILogChannel>();
            }

            var useColors = config.GetValue <bool>("logging:colors");

            services.AddSingletonAs(_ => new ConsoleLogChannel(useColors))
            .As <ILogChannel>();

            services.AddSingletonAs(_ => new ApplicationInfoLogAppender(typeof(LoggingServices).Assembly, Guid.NewGuid()))
            .As <ILogAppender>();

            services.AddSingletonAs <ActionContextLogAppender>()
            .As <ILogAppender>();

            services.AddSingletonAs <TimestampLogAppender>()
            .As <ILogAppender>();

            services.AddSingletonAs <DebugLogChannel>()
            .As <ILogChannel>();

            services.AddSingletonAs <SemanticLog>()
            .As <ISemanticLog>();

            services.AddSingletonAs <DefaultAppLogStore>()
            .As <IAppLogStore>();

            services.AddSingletonAs <BackgroundRequestLogStore>()
            .AsOptional <IRequestLogStore>();
        }
Ejemplo n.º 2
0
        public static void AddMyLoggingServices(this IServiceCollection services, IConfiguration config)
        {
            if (config.GetValue <bool>("logging:human"))
            {
                services.AddSingletonAs(JsonLogWriterFactory.Readable())
                .As <IObjectWriterFactory>();
            }
            else
            {
                services.AddSingletonAs(JsonLogWriterFactory.Default())
                .As <IObjectWriterFactory>();
            }

            var loggingFile = config.GetValue <string>("logging:file");

            if (!string.IsNullOrWhiteSpace(loggingFile))
            {
                services.AddSingletonAs(file ?? (file = new FileChannel(loggingFile)))
                .As <ILogChannel>();
            }

            var useColors = config.GetValue <bool>("logging:colors");

            if (console == null)
            {
                console = new ConsoleLogChannel(useColors);
            }

            services.AddSingletonAs(console)
            .As <ILogChannel>();

            services.AddSingletonAs(c => new ApplicationInfoLogAppender(typeof(Program).Assembly, Guid.NewGuid()))
            .As <ILogAppender>();

            services.AddSingletonAs <ActionContextLogAppender>()
            .As <ILogAppender>();

            services.AddSingletonAs <TimestampLogAppender>()
            .As <ILogAppender>();

            services.AddSingletonAs <DebugLogChannel>()
            .As <ILogChannel>();

            services.AddSingletonAs <SemanticLog>()
            .As <ISemanticLog>();

            services.AddSingletonAs <DefaultAppLogStore>()
            .As <IAppLogStore>();

            services.AddSingletonAs <NoopLogStore>()
            .As <ILogStore>();
        }
Ejemplo n.º 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingletonAs(_ => JsonLogWriterFactory.Readable())
            .As <IObjectWriterFactory>();

            services.AddSingletonAs(_ => new ConsoleLogChannel())
            .As <ILogChannel>();

            services.AddDefaultForwardRules();
            services.AddDefaultWebServices(configuration);

            services.AddSingletonAs <MyService1>();
            services.AddSingletonAs <MyService2>();

            services.AddInitializer();
            services.AddBackgroundProcesses();
        }
Ejemplo n.º 4
0
        private static void AddServices(this IServiceCollection services, IConfiguration config)
        {
            services.Configure <SemanticLogOptions>(config, "logging");
            services.Configure <SemanticLogDefaultOptions>(config, "logging");

            services.AddSingletonAs(c =>
            {
                var human = c.GetRequiredService <IOptions <SemanticLogDefaultOptions> >().Value.Human;

                return(human ? JsonLogWriterFactory.Readable() : JsonLogWriterFactory.Default());
            })
            .As <IObjectWriterFactory>();

            services.AddSingletonAs(c =>
            {
                var useColors = c.GetRequiredService <IOptions <SemanticLogDefaultOptions> >().Value.Colors;

                return(new ConsoleLogChannel(useColors));
            })
            .As <ILogChannel>();

            services.AddSingletonAs(c =>
            {
                var file = c.GetRequiredService <IOptions <SemanticLogDefaultOptions> >().Value.File;

                return(!string.IsNullOrWhiteSpace(file) ? (ILogChannel) new FileChannel(file) : new NoopChannel());
            })
            .As <ILogChannel>();

            services.AddSingletonAs <TimestampLogAppender>()
            .As <ILogAppender>();

            services.AddSingletonAs <DebugLogChannel>()
            .As <ILogChannel>();

            services.AddSingletonAs <SemanticLog>()
            .As <ISemanticLog>();
        }
Ejemplo n.º 5
0
        private static void AddServices(this IServiceCollection services, IConfiguration config)
        {
            services.Configure <SemanticLogOptions>(
                config.GetSection("logging"));

            if (config.GetValue <bool>("logging:human"))
            {
                services.AddSingletonAs(_ => JsonLogWriterFactory.Readable())
                .As <IObjectWriterFactory>();
            }
            else
            {
                services.AddSingletonAs(_ => JsonLogWriterFactory.Default())
                .As <IObjectWriterFactory>();
            }

            var loggingFile = config.GetValue <string>("logging:file");

            if (!string.IsNullOrWhiteSpace(loggingFile))
            {
                services.AddSingletonAs(_ => new FileChannel(loggingFile))
                .As <ILogChannel>();
            }

            var useColors = config.GetValue <bool>("logging:colors");

            services.AddSingletonAs(_ => new ConsoleLogChannel(useColors))
            .As <ILogChannel>();

            services.AddSingletonAs <TimestampLogAppender>()
            .As <ILogAppender>();

            services.AddSingletonAs <DebugLogChannel>()
            .As <ILogChannel>();

            services.AddSingletonAs <SemanticLog>()
            .As <ISemanticLog>();
        }