Пример #1
0
        public static void Check(this AliyunSlsNativeConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (string.IsNullOrWhiteSpace(config.LogStoreName))
            {
                throw new ArgumentNullException(nameof(config.LogStoreName));
            }

            if (string.IsNullOrWhiteSpace(config.EndPoint))
            {
                throw new ArgumentNullException(nameof(config.EndPoint));
            }

            if (string.IsNullOrWhiteSpace(config.ProjectName))
            {
                throw new ArgumentNullException(nameof(config.ProjectName));
            }

            if (string.IsNullOrWhiteSpace(config.AccessKeyId))
            {
                throw new ArgumentNullException(nameof(config.AccessKeyId));
            }

            if (string.IsNullOrWhiteSpace(config.AccessKey))
            {
                throw new ArgumentNullException(nameof(config.AccessKey));
            }
        }
Пример #2
0
        /// <summary>
        /// Use Aliyun SLS native config
        /// </summary>
        /// <param name="key"></param>
        /// <param name="nativeAct"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public AliyunSlsSinkOptions UseNativeConfig(string key, Action <AliyunSlsNativeConfig> nativeAct)
        {
            if (nativeAct == null)
            {
                throw new ArgumentNullException(nameof(nativeAct));
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            var cfg = new AliyunSlsNativeConfig();

            nativeAct(cfg);

            cfg.Check();

            if (AliyunSlsNativeConfigs.ContainsKey(key))
            {
                AliyunSlsNativeConfigs[key] = cfg;
            }
            else
            {
                AliyunSlsNativeConfigs.Add(key, cfg);
            }

            return(this);
        }
Пример #3
0
        public static bool IsValid(this AliyunSlsNativeConfig config)
        {
            if (config == null)
            {
                return(false);
            }

            try {
                config.Check();
            }
            catch {
                return(false);
            }

            return(true);
        }
        public static void SetSlsClient(string key, AliyunSlsNativeConfig 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 builder = LogServiceClientBuilders.HttpBuilder
                          .Endpoint(nativeConfig.EndPoint, nativeConfig.ProjectName)
                          .Credential(nativeConfig.AccessKeyId, nativeConfig.AccessKey);

            if (nativeConfig.Timeout >= 100)
            {
                builder.RequestTimeout(nativeConfig.Timeout);
            }

            if (nativeConfig.UseProxy)
            {
                builder.UseProxy(true);

                if (nativeConfig.ProxyUserEnabled)
                {
                    builder.Proxy(
                        nativeConfig.ProxyHost,
                        nativeConfig.ProxyPort,
                        nativeConfig.ProxyUserName,
                        nativeConfig.ProxyPassword,
                        nativeConfig.ProxyDomain);
                }
            }

            var instance = builder.Build();

            SetSlsClient(key, nativeConfig.LogStoreName, instance, nativeConfig.IsGeneralClient);
        }