Exemplo n.º 1
0
 public LogRecord(DateTime dateTime, ICollection <string> logStrings, LogRecordLevel recordType, ConsoleColor color)
 {
     DateTime   = dateTime;
     Color      = color;
     RecordType = recordType;
     LogStrings.AddRange(logStrings);
 }
 /// <summary>
 /// 将消息与异常写入到存储设备里前
 /// </summary>
 /// <param name="level">级别</param>
 /// <param name="msg">消息</param>
 /// <param name="eventId">事件ID</param>
 /// <param name="tags">标签</param>
 /// <param name="source">来源</param>
 /// <param name="ex">异常</param>
 protected virtual void BeforeWriteStorage(string level, string msg, string eventId, Exception ex = null, string source = null, params string[] tags)
 {
     if (LogLevelHelper.IsNeedWriteLog(level, LogRecordLevel.GetRecordLevel()))
     {
         WriteStorage(level, msg, eventId, ex.GetLastInnerException(), source, tags);
     }
 }
Exemplo n.º 3
0
        void TestLogRecord(LogRecordLevel writerLevel, LogRecordLevel recordLevel, bool isShouldBeNull)
        {
            var dt = DateTime.Now;
            var s  = new List <string> {
                writerLevel.ToString(), recordLevel.ToString()
            };
            var c = ConsoleColor.Red;

            _writer.LogLevel  = writerLevel;
            _writer.LogRecord = null;
            Assert.IsNull(_writer.LogRecord);
            var logRecord = new LogRecord(dt, new List <string>(s), recordLevel, c);

            Logger.Instance.AppendLog(logRecord);
            Thread.Sleep(10);  //Wait until async threads did their work
            if (isShouldBeNull)
            {
                Assert.IsNull(_writer.LogRecord);
            }
            else
            {
                Assert.IsNotNull(_writer.LogRecord);
                Assert.AreEqual(logRecord.Color, _writer.LogRecord?.Color);
                Assert.AreEqual(logRecord.RecordType, _writer.LogRecord?.RecordType);
                Assert.AreEqual(logRecord.LogStrings.Count, _writer.LogRecord?.LogStrings.Count);

                for (int j = 0; j < _writer.LogRecord.LogStrings.Count; j++)
                {
                    var strArr = _writer.LogRecord.LogStrings[j].Split('\t');
                    Assert.AreEqual(logRecord.LogStrings[j], strArr[strArr.Length - 1]);
                }
            }
        }
Exemplo n.º 4
0
        public ExceptionLogRecord(string message, LogRecordLevel logLevel, Exception exception, LogRecordDataValue[] dataValues)
        {
            Contract.Requires <ArgumentNullException>(exception != null);

            _message              = message;
            _logLevel             = logLevel;
            _exception            = exception;
            _additionalDataValues = dataValues;
            _dataValues           = null;
        }
Exemplo n.º 5
0
 public LogRecord(string message, LogRecordLevel logLevel, LogRecordDataValue[] dataValues)
 {
     _message    = message;
     _logLevel   = logLevel;
     _dataValues = dataValues;
 }