Esempio n. 1
0
        private void DoWork()
        {
            try
            {
                //Console.WriteLine("服务开始了吗");
                while (true)
                {
                    List <easy_log> logs = new List <easy_log>();
                    for (int i = 0; i < 100; i++)
                    {    //队列中取log
                        LogDto log = LogQueueInstance.GetLog();
                        if (log == null)
                        {
                            break;
                        }
                        if (log != null)
                        {
                            easy_log logModel = new easy_log();
                            logModel.log_summary = log.LogSummary;
                            logModel.log_message = log.LogMessage;
                            logModel.log_type    = log.LogType;
                            logModel.log_time    = log.LogTime;
                            logs.Add(logModel);
                        }
                    }
                    List <cms_visit> visits = new List <cms_visit>();

                    for (int i = 0; i < 100; i++)
                    {    //队列中取log
                        cms_visit visit = VisitQueueInstance.GetVisit();
                        if (visit == null)
                        {
                            break;
                        }
                        visits.Add(visit);
                    }
                    try
                    {
                        if (logs.Count > 0)
                        {
                            _freeSql.Insert(logs).ExecuteAffrows();
                        }
                        if (visits.Count > 0)
                        {
                            _freeSql.Insert(visits).ExecuteAffrows();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.ToString());
                    }
                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Esempio n. 2
0
 public static void Add(cms_visit log)
 {
     if (Queue.Count > 5000)
     {
         return;
     }
     Queue.Enqueue(log);
 }
Esempio n. 3
0
        /// <summary>
        /// 获取访问信息
        /// </summary>
        /// <returns></returns>
        public cms_visit Visit()
        {
            var model = new cms_visit();

            model.ip         = GetClientIp();
            model.visit_time = DateTime.Now;
            model.browser    = this.HttpRequest.Headers["User-Agent"];
            return(model);
        }