Example #1
0
        // 把累积的条目一次性写入日志文件
        public void WriteToLog(delegate_writeLog func_writeLog)
        {
            List <string> keys = new List <string>();

            _lock.EnterReadLock();
            try
            {
                foreach (string key in _table.Keys)
                {
                    CompactEntry entry = _table[key];
                    lock (entry)
                    {
                        entry.WriteToLog(func_writeLog);
                    }
                }
            }
            finally
            {
                _lock.ExitReadLock();
            }

            _lock.EnterWriteLock();
            try
            {
                foreach (string key in keys)
                {
                    _table.Remove(key);
                }
            }
            finally
            {
                _lock.ExitWriteLock();
            }
        }
Example #2
0
        string AddEntry(string fmt, object[] args)
        {
            CompactEntry entry = null;

            _lock.EnterWriteLock();
            try
            {
                if (_table.Count >= MaxEntryCount)
                {
                    return("Entry 数超过 " + MaxEntryCount + ",没有记入日志");
                }

                if (_table.ContainsKey(fmt) == false)
                {
                    entry = new CompactEntry {
                        Key = fmt, StartTime = DateTime.Now
                    };
                    _table.Add(fmt, entry);
                }
                else
                {
                    entry = (CompactEntry)_table[fmt];
                }
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            lock (entry)
            {
                entry.AddData(args);
            }

            return(null);
        }