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); } }
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); }
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); } }