Пример #1
0
        public void AddAsync(Level level, string msg)
        {
            Task.Run(() =>
            {
                int configLevel = Convert.ToInt32(Configer.Get("logLevel"));
                if ((int)level < configLevel)
                {
                    return;
                }

                Log model     = new Log();
                model.Level   = level.ToString();
                model.Logger  = "日志博客";
                model.Message = msg;
                Add(model);
            });
        }
Пример #2
0
        //为了保证日志不要太多,错误日志只保留前n条
        public int Add(Log model)
        {
            string cmdText = "insert into Log values(?,?,?,?,?);select last_insert_rowid() newid;";

            cmdText += $"DELETE FROM log where logid not in ( select LogId from Log order by date desc limit 0,{Configer.Get("logMaxCount")} )";
            object[] paramList =
            {
                null,      //对应的主键不要赋值了
                model.Date,
                model.Level,
                model.Logger,
                model.Message
            };
            object result = SQLiteHelper.ExecuteScalar(cmdText, paramList);

            int intResult;

            if (int.TryParse(result.ToString(), out intResult))
            {
                return(intResult);
            }
            return(0);
        }