コード例 #1
0
        public void DefaultFormatter()
        {
            DefaultLogFormatter formatter = new DefaultLogFormatter();

            Converts.Repository
            .Add(typeof(ExceptionModel), typeof(string), new ExceptionModelConverter());

            string   message;
            DateTime now = DateTime.Now;

            message = formatter.Format("Application", LogLevel.Debug, "M1");
            Assert.AreEqual(String.Format("{0} Application(DEBUG){1}{1}M1{1}", now, Environment.NewLine), message);

            message = formatter.Format("Application", LogLevel.Info, new ExceptionModel("M2", Ensure.Exception.NotImplemented()));
            Assert.AreEqual(String.Format("{0} Application(INFO){1}{1}M2{1}System.NotImplementedException: The method or operation is not implemented.{1}{1}", now, Environment.NewLine), message);
        }
コード例 #2
0
        public async void Append(string scopeName, LogLevel level, object model)
        {
            // TODO: Add support for paralel processing.
            Last = logFormatter.Format(scopeName, level, model);
            await Task.Delay(3000);

            Last = null;
        }
コード例 #3
0
        public void MustReturnRawTextForLogMessage()
        {
            var sut   = new DefaultLogFormatter();
            var entry = new LogText("Must return this text...");

            var text = sut.Format(entry);

            Assert.AreEqual(entry.Text, text);
        }
コード例 #4
0
        public void MustCorrectlyFormatLogMessage()
        {
            var sut        = new DefaultLogFormatter();
            var date       = new DateTime(2017, 10, 10, 15, 24, 38);
            var threadInfo = new ThreadInfo(1234, "ABC");
            var entry      = new LogMessage(date, LogLevel.Warning, "Here's a warning message...", threadInfo);

            var text = sut.Format(entry);

            Assert.AreEqual($"2017-10-10 15:24:38.000 [1234: ABC] - WARNING: Here's a warning message...", text);
        }
コード例 #5
0
        public void ShouldFormatWithNullInput()
        {
            ILogFormatter formatter;
            DateTime      dateTime;


            formatter = new DefaultLogFormatter();
            dateTime  = DateTime.Now;

            Assert.AreEqual($"{dateTime} | Debug | 1 | Undefined | Undefined | Undefined", formatter.Format(new Log(dateTime, 1, null, null, LogLevels.Debug, null)));
        }
コード例 #6
0
        public void ShouldFormatWithValidInput()
        {
            ILogFormatter formatter;
            DateTime      dateTime;


            formatter = new DefaultLogFormatter();
            dateTime  = DateTime.Now;

            Assert.AreEqual($"{dateTime} | Debug | 1 | Component | Method | Message", formatter.Format(new Log(dateTime, 1, "Component", "Method", LogLevels.Debug, "Message")));
        }
コード例 #7
0
        public void MustReportNotYetImplementedLogContent()
        {
            var sut = new DefaultLogFormatter();

            sut.Format(new NewLogContentType());
        }