/// <summary> /// Add Aliyun SLS support for Cosmos Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddAliyunSls(this ILogServiceCollection services, Action <AliyunSlsSinkOptions> settingAct = null, Action <IConfiguration, AliyunSlsSinkConfiguration> configAct = null) { var settings = new AliyunSlsSinkOptions(); settingAct?.Invoke(settings); return(services.AddAliyunSls(settings, configAct)); }
private void MergeAliyunSlsNativeConfig(AliyunSlsSinkOptions 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(AliyunSlsSinkOptions options) { if (options.HasLegalNativeConfig(false)) { return; } if (options.HasLegalNativeConfig(true)) { return; } options.UseNativeConfig(Constants.DefaultClient, c => { c.LogStoreName = options.LogStoreName; c.EndPoint = options.EndPoint; c.ProjectName = options.ProjectName; c.AccessKeyId = options.AccessKeyId; c.AccessKey = options.AccessKey; c.IsGeneralClient = true; }); }
private static void RegisterAliyunSlsClients(AliyunSlsSinkOptions options) { if (!options.HasLegalNativeConfig(false)) { throw new InvalidOperationException("There is no legal Alibaba Cloud (Aliyun) SLS native config."); } if (options.AliyunSlsNativeConfigs.Any()) { foreach (var kvp in options.AliyunSlsNativeConfigs) { AliyunSlsClientManager.SetSlsClient(kvp.Key, kvp.Value); } } else { AliyunSlsClientManager.SetSlsClient(Constants.DefaultClient, options.LogStoreName, options.EndPoint, options.ProjectName, options.AccessKeyId, options.AccessKey, true); } }
/// <summary> /// Add Aliyun SLS support for Cosmos Logging /// </summary> /// <param name="services"></param> /// <param name="sinkOptions"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddAliyunSls(this ILogServiceCollection services, AliyunSlsSinkOptions sinkOptions, Action <IConfiguration, AliyunSlsSinkConfiguration> configAct = null) { return(services.AddAliyunSls(Options.Create(sinkOptions), configAct)); }