예제 #1
0
        public void Log(LogLevel logLevel, string message)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var formattedMessage = LogFormatterHelper.Format(Name, logLevel, message, DateTime.UtcNow);

            if (!string.IsNullOrEmpty(formattedMessage))
            {
                WriteMessage(formattedMessage, logLevel);
            }
        }
예제 #2
0
        public void Formatter_should_return_with_the_proper_formatted_text()
        {
            string   name    = "Name";
            LogLevel level   = LogLevel.Debug;
            string   message = "Log Message";
            DateTime time    = DateTime.UtcNow;

            string resultText = LogFormatterHelper.Format(name, level, message, time);


            Assert.NotNull(resultText);
            Assert.NotEmpty(resultText);
            string format = $"[{name}]: {time.ToUniversalTime()} [debug] {message}";

            Assert.Equal(resultText, format);
        }
예제 #3
0
        public void Log(LogLevel logLevel, string message)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var formattedMessage = LogFormatterHelper.Format(Name, logLevel, message, DateTime.UtcNow);

            //we just trim the message if it is longer the 1000 char. We don't want to throw exception
            if (formattedMessage.Length > 1000)
            {
                formattedMessage = formattedMessage.Substring(0, 1000);
            }
            if (!string.IsNullOrEmpty(formattedMessage))
            {
                WriteMessage(formattedMessage, logLevel);
            }
        }