Esempio n. 1
0
        /// <summary>
        /// 处理日志
        /// </summary>
        /// <param name="loggingEvent"></param>
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (httpUtil is null)
            {
                CreateHttpUtil();
            }
            var loginfo = loggingEvent.ToLoggerInfo(Application);

            if (loginfo != null)
            {
                var  jsonData   = loginfo.ToJson();
                var  times      = 0;
                bool isComplete = false;
                do
                {
                    if (times > 0)
                    {
                        Thread.Sleep(1000);
                    }
                    times++;
#if NET40
                    isComplete = httpUtil.PostData(Target, jsonData, IsCompress);
#else
                    isComplete = httpUtil.PostDataAsync(Target, jsonData, IsCompress).Result;
#endif
                } while (!isComplete && times <= 3);//如果失败尝试3次
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 将日志日志推送至服务器
        /// </summary>
        private void PushToServer()
        {
            string jsonData = string.Empty;

            lastPushTime = DateTime.Now;
            if (logBuffer.Count <= 0)
            {
                return;
            }
            var lst  = new List <LoggerInfo>();
            var size = Math.Min(MaxPushSize, logBuffer.Count);

            for (int i = 0; i < size; i++)
            {
                lst.Add(logBuffer.Take());
            }
            //Console.WriteLine(lst.Count);
            jsonData = JsonConvert.SerializeObject(lst);
            //logBuffer.Clear();
            if (!string.IsNullOrEmpty(jsonData))
            {
                if (httpUtil is null)
                {
                    CreateHttpUtil();
                }
                var isCompress = false;
                var target     = Target;
                if (jsonData.Length > 1024)//超过1024字节(1K)
                {
                    isCompress = true;
                    target     = CompressTarget;
                }
                var times      = 0;
                var isComplete = false;
                do
                {
                    if (times > 0)
                    {
                        Thread.Sleep(1000);
                    }
                    times++;
#if NET40
                    isComplete = httpUtil.PostData(target, jsonData, isCompress);
#else
                    isComplete = httpUtil.PostDataAsync(target, jsonData, isCompress).Result;
#endif
                } while (!isComplete && times <= 3);//如果失败尝试3次
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 将日志日志推送至服务器
        /// </summary>
        private void PushToServer()
        {
            string jsonData = string.Empty;

            lastPushTime = DateTime.Now;
            lock (logBuffer)
            {
                if (logBuffer.Count <= 0)
                {
                    return;
                }
                jsonData = JsonConvert.SerializeObject(logBuffer);
                logBuffer.Clear();
            }
            if (!string.IsNullOrEmpty(jsonData))
            {
                if (httpUtil is null)
                {
                    CreateHttpUtil();
                }
                var isCompress = false;
                var target     = Target;
                if (jsonData.Length > 1024)//超过1024字节(1K)
                {
                    isCompress = true;
                    target     = CompressTarget;
                }
                var times      = 0;
                var isComplete = false;
                do
                {
                    if (times > 0)
                    {
                        Thread.Sleep(1000);
                    }
                    times++;
                    isComplete = httpUtil.PostDataAsync(target, jsonData, isCompress).Result;
                } while (!isComplete && times <= 3);//如果失败尝试3次
            }
        }