// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschränkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Squidex.Infrastructure; using Squidex.Infrastructure.Log; using Squidex.Pipeline; #pragma warning disable RECS0092 // Convert field to readonly namespace Squidex.Config.Domain { public static class LoggingServices { private static ILogChannel console = new ConsoleLogChannel(); private static ILogChannel file; public static void AddMyLoggingServices(this IServiceCollection services, IConfiguration config) { if (config.GetValue("logging:human")) { services.AddSingletonAs(c => new Func(() => new JsonLogWriter(Formatting.Indented, true))); } else { services.AddSingletonAs(c => new Func(() => new JsonLogWriter())); } var loggingFile = config.GetValue("logging:file"); if (!string.IsNullOrWhiteSpace(loggingFile)) { services.AddSingletonAs(file ?? (file = new FileChannel(loggingFile))) .As(); } var useColors = config.GetValue("logging:colors"); if (console == null) { console = new ConsoleLogChannel(useColors); } services.AddSingletonAs(console) .As(); services.AddSingletonAs(c => new ApplicationInfoLogAppender(typeof(Program).Assembly, Guid.NewGuid())) .As(); services.AddSingletonAs() .As(); services.AddSingletonAs() .As(); services.AddSingletonAs() .As(); services.AddSingletonAs() .As(); } } }