/// <summary> /// Add JdCloud Log service support for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddJdCloudLogService(this ILogServiceCollection services, Action <JdCloudLogSinkOptions> settingAct = null, Action <IConfiguration, JdCloudLogSinkConfiguration> configAct = null) { var settings = new JdCloudLogSinkOptions(); settingAct?.Invoke(settings); return(services.AddJdCloudLogService(settings, configAct)); }
private void MergeJdCloudNativeConfig(JdCloudLogSinkOptions options) { PrepareForNativeClientInOptions(options); if (Clients != null) { foreach (var kvp in Clients.Where(o => !string.IsNullOrWhiteSpace(o.Key) && o.Value.IsValid())) { options.UseNativeConfig(kvp.Key, c => c.SetMySelf(kvp.Value)); } } else if (Client != null) { options.UseNativeConfig(Client.Key, c => c.SetMySelf(Client)); } }
private static void RegisterJdCloudLogClients(JdCloudLogSinkOptions options) { if (!options.HasLegalNativeConfig(false)) { throw new InvalidOperationException("There is no legal JD Cloud Log Service native config."); } if (options.JdCloudLogNativeConfigs.Any()) { foreach (var kvp in options.JdCloudLogNativeConfigs) { JdCloudLogClientManager.SetLogClient(kvp.Key, kvp.Value); } } else { JdCloudLogClientManager.SetLogClient(Constants.DefaultClient, options.LogStreamName, options.AccessKey, options.SecretKey, options.Security, options.RequestTimeout, true); } }
private static void PrepareForNativeClientInOptions(JdCloudLogSinkOptions options) { if (options.HasLegalNativeConfig(false)) { return; } if (options.HasLegalNativeConfig(true)) { return; } options.UseNativeConfig(Constants.DefaultClient, c => { c.LogStreamName = options.LogStreamName; c.SecretKey = options.SecretKey; c.AccessKey = options.AccessKey; c.RetryTimes = options.RetryTimes; c.RequestTimeout = options.RequestTimeout; c.Security = options.Security; c.IsGeneralClient = true; }); }
/// <summary> /// Add JdCloud Log service support for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="sinkOptions"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddJdCloudLogService(this ILogServiceCollection services, JdCloudLogSinkOptions sinkOptions, Action <IConfiguration, JdCloudLogSinkConfiguration> configAct = null) { return(services.AddJdCloudLogService(Options.Create(sinkOptions), configAct)); }