/// <summary> /// Use JdCloud Log Service native config /// </summary> /// <param name="key"></param> /// <param name="nativeAct"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public JdCloudLogSinkOptions UseNativeConfig(string key, Action <JdCloudNativeConfig> nativeAct) { if (nativeAct == null) { throw new ArgumentNullException(nameof(nativeAct)); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } var cfg = new JdCloudNativeConfig(); nativeAct(cfg); cfg.Check(); if (JdCloudLogNativeConfigs.ContainsKey(key)) { JdCloudLogNativeConfigs[key] = cfg; } else { JdCloudLogNativeConfigs.Add(key, cfg); } return(this); }
public static void SetLogClient(string key, JdCloudNativeConfig nativeConfig) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (nativeConfig == null) { throw new ArgumentNullException(nameof(nativeConfig)); } nativeConfig.Check(); if (key == Constants.GeneralClientKey) { throw new ArgumentException($"Key cannot be same as '{Constants.GeneralClientKey}'."); } var credentialsProvider = new StaticCredentialsProvider(nativeConfig.AccessKey, nativeConfig.SecretKey); var instance = new JDCloudSDK.Logs.Client.LogsClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(nativeConfig.Security ? Protocol.HTTPS : Protocol.HTTP, nativeConfig.RequestTimeout)) .Build(); SetLogClient(key, nativeConfig.LogStreamName, instance, nativeConfig.IsGeneralClient); }
public static bool IsValid(this JdCloudNativeConfig config) { if (config == null) { return(false); } try { config.Check(); } catch { return(false); } return(true); }
public static void Check(this JdCloudNativeConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (string.IsNullOrWhiteSpace(config.LogStreamName)) { throw new ArgumentNullException(nameof(config.LogStreamName)); } if (string.IsNullOrWhiteSpace(config.AccessKey)) { throw new ArgumentNullException(nameof(config.AccessKey)); } if (string.IsNullOrWhiteSpace(config.SecretKey)) { throw new ArgumentNullException(nameof(config.SecretKey)); } }