/// <summary> /// Add Tencent Cloud CLS support for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddTencentCloudCls(this ILogServiceCollection services, Action <TencentCloudClsSinkOptions> settingAct = null, Action <IConfiguration, TencentCloudClsSinkConfiguration> configAct = null) { var settings = new TencentCloudClsSinkOptions(); settingAct?.Invoke(settings); return(services.AddTencentCloudCls(settings, configAct)); }
private void MergeTencentCloudClsNativeConfig(TencentCloudClsSinkOptions 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 PrepareForNativeClientInOptions(TencentCloudClsSinkOptions options) { if (options.HasLegalNativeConfig(false)) { return; } if (options.HasLegalNativeConfig(true)) { return; } options.UseNativeConfig(Constants.DefaultClient, c => { c.RequestUri = options.RequestUri; c.SecretId = options.SecretId; c.SecretKey = options.SecretKey; c.TopicId = options.TopicId; c.RequestTimeout = options.RequestTimeout; c.IsGeneralClient = true; }); }
private static void RegisterTencentCloudClsClients(TencentCloudClsSinkOptions options) { if (!options.HasLegalNativeConfig(false)) { throw new InvalidOperationException("There is no legal JD Cloud Log Service native config."); } if (options.TencentCloudClsNativeConfigs.Any()) { foreach (var kvp in options.TencentCloudClsNativeConfigs) { TencentCloudClsClientManager.SetClsClient(kvp.Key, kvp.Value); } } else { TencentCloudClsClientManager.SetClsClient(Constants.DefaultClient, options.RequestUri, options.SecretId, options.SecretKey, options.TopicId, options.RequestTimeout, true); } }
/// <summary> /// Add Tencent Cloud CLS support for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="sinkOptions"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddTencentCloudCls(this ILogServiceCollection services, TencentCloudClsSinkOptions sinkOptions, Action <IConfiguration, TencentCloudClsSinkConfiguration> configAct = null) { return(services.AddTencentCloudCls(Options.Create(sinkOptions), configAct)); }