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());
            }
        }
Beispiel #2
0
        private void DoWork()
        {
            try
            {
                //Console.WriteLine("服务开始了吗");
                while (true)
                {
                    List <easy_log>    logs    = new List <easy_log>();
                    List <sys_sql_log> sqllogs = new List <sys_sql_log>();
                    for (int i = 0; i < 300; i++)
                    {    //队列中取log
                        LogDto log = LogQueueInstance.GetLog();
                        if (log == null)
                        {
                            break;
                        }
                        if (log.LogType == 5)
                        {
                            sys_sql_log sqllog = new sys_sql_log();
                            sqllog.table_name   = log.LogSummary;
                            sqllog.sql_string   = log.LogMessage;
                            sqllog.excute_time  = log.LogTime;
                            sqllog.elapsed_time = log.ElapsedTime;
                            sqllogs.Add(sqllog);
                        }
                        else
                        {
                            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();
                        //}
                        if (sqllogs.Count > 0)
                        {
                            _freeSql.Insert(sqllogs).ExecuteAffrows();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.ToString());
                    }
                    Thread.Sleep(5000);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Beispiel #3
0
        private void DoWork()
        {
            try
            {
                //Console.WriteLine("服务开始了吗");
                while (true)
                {
                    List <easy_log>        logs    = new List <easy_log>(300);
                    List <sys_sql_log>     sqllogs = new List <sys_sql_log>(300);
                    List <crontab_history> jobLogs = new List <crontab_history>(300);
                    for (int i = 0; i < 300; i++)
                    {    //队列中取log
                        LogDto log = LogQueueInstance.GetLog();
                        if (log == null)
                        {
                            break;
                        }
                        if (log.LogType == 6)
                        {
                            crontab_history crontabModel = new crontab_history();
                            crontabModel.job_id        = log.LogSummary;
                            crontabModel.error_message = log.LogMessage;
                            crontabModel.excute_time   = log.LogTime;
                            crontabModel.excute_result = log.ExcuteResult;
                            if (log.ElapsedTime < 1000)
                            {
                                crontabModel.elapsed_time = $"{log.ElapsedTime}毫秒";
                            }
                            else
                            {
                                decimal elaspedSeconds = Math.Round((decimal)log.ElapsedTime / 1000, 1);
                                crontabModel.elapsed_time = $"{elaspedSeconds}秒";
                            }

                            jobLogs.Add(crontabModel);
                            continue;
                        }
                        if (log.LogType == 5)
                        {
                            sys_sql_log sqllog = new sys_sql_log();
                            sqllog.table_name   = log.LogSummary;
                            sqllog.sql_string   = log.LogMessage;
                            sqllog.excute_time  = log.LogTime;
                            sqllog.elapsed_time = log.ElapsedTime;
                            sqllogs.Add(sqllog);
                        }
                        else
                        {
                            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();
                        //}
                        if (sqllogs.Count > 0)
                        {
                            _freeSql.Insert(sqllogs).ExecuteAffrows();
                        }

                        if (jobLogs.Count > 0)
                        {
                            _freeSql.Insert(jobLogs).ExecuteAffrows();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.ToString());
                    }
                    Thread.Sleep(5000);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }