Ejemplo n.º 1
0
        private readonly string sql       = "";          // 日志sql语句
        public DbLogEventHandler(LoggingDbOptions dbLogOptions)
        {
            _dbLogOptions = dbLogOptions;
            if (_dbLogOptions.IsDbSharding)
            {
                switch (_dbLogOptions.DbShardingRule)
                {
                case 1:
                    tableName = tableName + "_" + DbShardingHelper.DayRule(DateTime.Now);
                    break;

                case 2:
                    tableName = tableName + "_" + DbShardingHelper.MonthRule(DateTime.Now);
                    break;
                }
            }
            sql = string.Format(@"INSERT INTO {0} (Id,AddTime,ClassName,ProjectName, LogTag, LogType, LogMessage, IP) 
                                      VALUES (@Id,@AddTime,@ClassName,@ProjectName, @LogTag, @LogType, @LogMessage, @IP)"
                                , tableName);
        }
        public void AddCollect(DbConn PubConn, tb_performance_collect_model model)
        {
            SqlHelper.Visit(ps =>
            {
                //服务器id
                ps.Add("@serverid", model.serverid);
                //cpu信息
                ps.Add("@cpu", model.cpu);
                //内存字节
                ps.Add("@memory", model.memory);
                //网络上传字节
                ps.Add("@networkupload", model.networkupload);
                //网络下载字节
                ps.Add("@networkdownload", model.networkdownload);
                //io读字节
                ps.Add("@ioread", model.ioread);
                //io写字节
                ps.Add("@iowrite", model.iowrite);
                //
                ps.Add("@iisrequest", model.iisrequest);
                //创建时间
                ps.Add("@createtime", model.createtime);
                return(PubConn.ExecuteSql(string.Format(@"insert into tb_performance_collect{0}(serverid,cpu,memory,networkupload,networkdownload,ioread,iowrite,iisrequest,createtime)
										   values(@serverid,@cpu,@memory,@networkupload,@networkdownload,@ioread,@iowrite,@iisrequest,@createtime)"                                        , DbShardingHelper.DayRule(DateTime.Now)), ps.ToParameters()));
            });
        }