Esempio n. 1
0
        /// <summary>
        /// Write the log for warning message
        /// </summary>
        /// <param name="message">The message for warning.</param>
        public void WriteWarn(string message)
        {
            LogItem item = new LogItem();
            item.Time = DateTime.Now;
            item.Level = LogLevel.Warning;
            item.Message = message;

            lock (_logQueue)
            {
                _logQueue.Enqueue(item);
                if (_logQueue.Count > LogConfig.LogCapacityEachBlock)
                    Monitor.Pulse(_logQueue);
            }
        }
Esempio n. 2
0
 public void WriteLogItem(LogItem item)
 {
     _writer.Write(item.Time.ToBinary());
     _writer.Write((int)item.Level);
     _writer.Write(item.Message);
 }
Esempio n. 3
0
        public List<LogItem> GetLog(DateTime time)
        {
            DirectoryInfo di = new DirectoryInfo(LogConfig.LogDir);
            FileInfo[] fis = di.GetFiles(string.Format("{0:yyyyMMdd}*", time));
            List<LogItem> logitems = new List<LogItem>();
            foreach (FileInfo fi in fis)
            {
                BinaryReader sr = new BinaryReader(fi.OpenRead());
                while (sr.BaseStream.Position < fi.Length)
                {
                    LogItem item = new LogItem();
                    item.Time = DateTime.FromBinary(sr.ReadInt64());
                    item.Level = (LogLevel)sr.ReadInt32();
                    item.Message = sr.ReadString();
                    logitems.Add(item);
                }
                sr.Close();
            }

            return logitems;
        }
Esempio n. 4
0
        /// <summary>
        /// Get the log identify be id.
        /// </summary>
        /// <param name="id">the file name</param>
        /// <returns></returns>
        public List<LogItem> GetLog(string id)
        {
            //for FileLog, id refer the file name.
            if (!File.Exists(id))
                throw new FileNotFoundException(string.Format("The file {0} is not exist!", id));

            List<LogItem> logitems = new List<LogItem>();
            FileInfo fi = new FileInfo(id);
            BinaryReader sr = new BinaryReader(fi.OpenRead());
            while (sr.BaseStream.Position < fi.Length)
            {
                LogItem item = new LogItem();
                item.Time = DateTime.FromBinary(sr.ReadInt64());
                item.Level = (LogLevel)sr.ReadInt32();
                item.Message = sr.ReadString();
                logitems.Add(item);
            }

            return logitems;
        }