Пример #1
0
 public LogEventInfo(LogLevel level, string logger, string message, Exception ex)
 {
     Level      = level;
     Logger     = logger;
     Message    = message;
     Exception  = ex;
     TimeStamp  = LogManagerBase.GetDateTime();
     SequenceID = GetNextSequenceId();
 }
Пример #2
0
        public void TestTimestampBoth()
        {
            var naming = new FileNamingParameters()
            {
                IncludeLevel     = false,
                IncludeLogger    = false,
                IncludeSequence  = false,
                IncludeSession   = false,
                IncludeTimestamp = FileTimestampMode.DateTime
            };

            // ok...
            var info = GetLogEventInfo();

            // check...
            var filename = naming.GetFilename(new LogWriteContext(), info);

            Assert.Equal(string.Format("Log - {0}.log", LogManagerBase.GetDateTime().ToString("yyyyMMdd HHmmss")), filename);
        }
Пример #3
0
        public void TestEverythingOn()
        {
            var naming = new FileNamingParameters()
            {
                IncludeLevel     = true,
                IncludeLogger    = true,
                IncludeSequence  = true,
                IncludeSession   = true,
                IncludeTimestamp = FileTimestampMode.DateTime
            };

            // ok...
            var info = GetLogEventInfo();

            // check...
            var context  = new LogWriteContext();
            var filename = naming.GetFilename(context, info);

            Assert.Equal(string.Format("Log - INFO - foobar - {0} - {1} - {2}.log", LogManagerBase.GetDateTime().ToString("yyyyMMdd HHmmss"),
                                       context.Environment.SessionId, info.SequenceID), filename);
        }
Пример #4
0
        public void Log(LogLevel logLevel, string message, Exception ex)
        {
            string formatted = null;
            long   sequence  = LogEventInfo.GetNextSequenceId();
            string dt        = LogManagerBase.GetDateTime().ToString(LogManagerBase.DateTimeFormat);
            string asString  = logLevel.ToString().ToUpper();
            int    thread    = Environment.CurrentManagedThreadId;

            if (ex != null)
            {
                formatted = string.Format("{0}|{1}|{2}|{3}|{4} --> {5}", sequence, dt, asString, thread, message, ex);
            }
            else
            {
                formatted = string.Format("{0}|{1}|{2}|{3}|{4}", sequence, dt, asString, thread, message);
            }

            // debug...
            System.Diagnostics.Debug.WriteLine(formatted);
            // TODO: EWT
        }