public void GetLogLineTestWithParams() { DefaultLogFormatter dlf = new DefaultLogFormatter(); Guid id = new Guid(); string message = "info-message"; var contextParameters = new Dictionary <string, string> { { "isDev", "true" }, { "isProduction", "false" } }; var sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine($" [ID] = {id}"); sb.AppendLine($" [LEVEL] = {LogLevel.Info.ToString().ToUpperInvariant()}"); sb.AppendLine($" [TIME] = {DateTime.UtcNow}"); sb.AppendLine($" [MESSAGE] = {message}"); foreach (var contextParameter in contextParameters) { sb.AppendLine($" [{contextParameter.Key}] = {contextParameter.Value}"); } sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("--------------------------------------------------------------------------------"); sb.AppendLine(); string expected = sb.ToString(); string actual = dlf.GetLogLine(id, LogLevel.Info, "info-message", contextParameters); Assert.Equal(expected, actual); }
private ILogger BuildLogger() { var formatter = new DefaultLogFormatter(); var logger = new MultiLogger(); logger.Loggers.Add(new ConsoleLogger(formatter)); logger.Loggers.Add(new FileLogger(Path.Combine(Path.GetTempPath(), "HerdLogs"), formatter)); return(logger); }
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); }
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))); }
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"))); }
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); }
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); }
public static void Test() { XmlConfigurator.Configure(); Converts.Repository .Add(typeof(ExceptionModel), typeof(string), new ExceptionModelConverter()); ILogFormatter formatter = new DefaultLogFormatter(); ILogFactory logFactory = new DefaultLogFactory() .AddConsole(formatter) .AddLog4net(); ILog root = logFactory.Scope("Root"); root.Debug("Hello, World!"); root.Fatal(Ensure.Exception.NotImplemented()); root.Fatal(Ensure.Exception.NotImplemented(), "Method is not implemented!"); }
public void GetLogLineTestNoParams() { DefaultLogFormatter dlf = new DefaultLogFormatter(); Guid id = new Guid(); string message = "info-message"; var sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine($" [ID] = {id}"); sb.AppendLine($" [LEVEL] = {LogLevel.Info.ToString().ToUpperInvariant()}"); sb.AppendLine($" [TIME] = {DateTime.UtcNow}"); sb.AppendLine($" [MESSAGE] = {message}"); sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("--------------------------------------------------------------------------------"); sb.AppendLine(); string expected = sb.ToString(); string actual = dlf.GetLogLine(id, LogLevel.Info, "info-message", null); Assert.Equal(expected, actual); }
public void MustReportNotYetImplementedLogContent() { var sut = new DefaultLogFormatter(); sut.Format(new NewLogContentType()); }
static LoggingService() { Formatter = new DefaultLogFormatter(); DefaultTarget = new ConsoleLogTarget(); }
public DebugLogOutput() { Formatter = new DefaultLogFormatter(); }
public void SetUp() { _formatter = new DefaultLogFormatter(); }