public void GetMessageMustNotLogExceptionWhenExceptionIsNull() { DateTime now = DateTime.UtcNow; StubConsoleLoggerFormatter formatter = new StubConsoleLoggerFormatter(now); string message = formatter.GetMessage(nameof(ConsoleLoggerFormatterTests), LogLevel.Information, "Test", null); Assert.Matches($@"(?s)^{now:O} Information {nameof(ConsoleLoggerFormatterTests)} \[.*\] Test$", message); }
public void GetMessageMustLogExceptionWhenExceptionIsNotNull() { DateTime now = DateTime.UtcNow; StubConsoleLoggerFormatter formatter = new StubConsoleLoggerFormatter(now); string message = formatter.GetMessage(nameof(ConsoleLoggerFormatterTests), LogLevel.Information, "Test", new Exception("Test")); Assert.Matches($@"(?s)^{now:O} Information {nameof(ConsoleLoggerFormatterTests)} \[.*\] Test{Environment.NewLine}System.Exception: Test.*$", message); }
public void GetThreadIdMustReturnThreadNameWhenThreadNameIsNotEmpty() { bool result = false; Thread thread = new Thread(() => { try { string threadId = new StubConsoleLoggerFormatter().InvokeGetThreadId(); result = threadId == "Test"; } catch { result = false; } }) { IsBackground = true, Name = "Test" }; thread.Start(); thread.Join(); Assert.True(result); }