예제 #1
0
        public virtual void Init(WriterSection config)
        {
            // 避免重复调用
            if (s_client != null)
            {
                return;
            }

            HttpWriterClient client = ObjectFactory.New <HttpWriterClient>();

            client.Init(config);

            s_client = client;
        }
예제 #2
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="config"></param>
        public void Init(WriterSection config)
        {
            // 避免重复调用
            if (s_url != null)
            {
                return;
            }


            string url = config.GetOptionValue("url");

            if (string.IsNullOrEmpty(url))
            {
                throw new LogConfigException("日志配置文件中,没有为HttpWriter指定url属性。");
            }

            string format = config.GetOptionValue("format");

            if (string.IsNullOrEmpty(format))
            {
                s_format = SerializeFormat.Xml;     // 默认值
            }
            else
            {
                if (Enum.TryParse <SerializeFormat>(format, out s_format) == false ||
                    s_format == SerializeFormat.None ||
                    s_format == SerializeFormat.Auto
                    )
                {
                    throw new LogConfigException("日志配置文件中,为HttpWriter指定的format属性无效,建议选择:Json or Xml");
                }
            }

            s_retryCount           = config.GetOptionValue("retry-count").TryToUInt(10);
            s_retryWaitMillisecond = config.GetOptionValue("retry-wait-millisecond").TryToUInt(1000);
            s_datatypeInHeader     = config.GetOptionValue("datatype-in-header").TryToBool(true);

            List <NameValue> queryString = ReadHttpArgs(config, "querystring:");

            s_header = ReadHttpArgs(config, "header:");

            s_url    = url.ConcatQueryStringArgs(queryString);
            s_client = new HttpWriterClient();
        }