internal static LoggerConfiguration ConfigureLoki(this LoggerConfiguration configuration, LokiOptions lokiOptions, bool dynamicLevel) { if (lokiOptions is null || lokiOptions.Enabled is false) { return(configuration); } if (string.IsNullOrEmpty(lokiOptions.Endpoint)) { throw new TitanException("Loki cannot be null or empty."); } LokiCredentials credentials; if (lokiOptions.Credentials is null) { credentials = new NoAuthCredentials(lokiOptions.Endpoint); } else { credentials = new BasicAuthCredentials(lokiOptions.Endpoint, lokiOptions.Credentials.Username, lokiOptions.Credentials.Password); } configuration.WriteTo.TitanLoki(credentials, null, null, TitanLibHelper.GetLogLevel(lokiOptions.LogLevelRestriction), lokiOptions.BatchSizeLimit, lokiOptions.Period.ToTimeSpan(), lokiOptions.QueueLimit, dynamicLevel); return(configuration); }
private static void ConfigureMinimumLevels(LoggerConfiguration config, TitanOptions options) { if (options.DynamicDefaultLevel) { config.MinimumLevel.ControlledBy(new LoggingLevelSwitch(TitanLibHelper.GetLogLevel(options.DefaultLevel))); } else { config.MinimumLevel.Is(TitanLibHelper.GetLogLevel(options.DefaultLevel)); } config .MinimumLevel.Override("System", TitanLibHelper.GetLogLevel(options.Overrides.System)) .MinimumLevel.Override("Microsoft", TitanLibHelper.GetLogLevel(options.Overrides.Microsoft)) .MinimumLevel.Override("Microsoft.AspNetCore", TitanLibHelper.GetLogLevel(options.Overrides.AspNetCore)) .MinimumLevel.Override("Microsoft.Hosting.Lifetime", TitanLibHelper.GetLogLevel(options.Overrides.MicrosoftHostingLifetime)); foreach (string[] item in options.Overrides.Custom.Select(s => s.Split(":"))) { config.MinimumLevel.Override(item[0], TitanLibHelper.GetLogLevel(item[1])); } }