/// <summary>
        /// 日志写入数据库
        /// </summary>
        /// <param name="state"></param>
        void timeoutCallback(object state)
        {
            LogModelTimer logModelTimer = (LogModelTimer)state;
            var           key           = logModelTimer.GetLogKey();

            if (LogStorage.Logs.TryRemove(key, out LogModelTimer outLog))
            {
                BsonDocument log = outLog.LogModel.ToBsonDocument();
                log.Remove("_id");
                new Log().Insert(log);
                outLog.timer.Dispose();
            }
        }
Exemple #2
0
        public void Worker(LogModel logModel)
        {
            LogModelTimer logModelTimer = new LogModelTimer(logModel);
            string        key           = logModelTimer.GetLogKey();

            if (!LogStorage.Logs.ContainsKey(key))
            {
                bool result = LogStorage.Logs.TryAdd(key, logModelTimer);
            }
            else
            {
                var currentLog = LogStorage.Logs[key].LogModel;
                currentLog.CountPerMinute++;
                currentLog.Time = (currentLog.Time + logModel.Time) / 2;
            }
        }