public void AppendTest() { var myPath = $"{typeof(FileLoggerBaseTest).Namespace}.{nameof(AppendTest)}.log"; try { var testedFileLogger = new FileLoggerBase(myPath); var expectedError1 = new Exception("testError1"); var expectedError2 = "testError2"; var expectedWarning = "testWarning1"; var expectedinfo = "testInfo1"; testedFileLogger.LogError(expectedError1); testedFileLogger.LogError(expectedError2); testedFileLogger.LogWarning(expectedWarning); testedFileLogger.LogInfo(expectedinfo); var received = File.ReadAllText(myPath); Assert.True(File.Exists(myPath)); Assert.Contains(expectedError1.Message, received); Assert.Contains(expectedError2, received); Assert.Contains(expectedWarning, received); Assert.Contains(expectedinfo, received); Assert.Contains(MessageSeverity.Error.ToString(), received); Assert.Contains(MessageSeverity.Information.ToString(), received); Assert.Contains(MessageSeverity.Warning.ToString(), received); } finally { File.Delete(myPath); } }
public void LogError2() { var myPath = $"{typeof(FileLoggerBaseTest).Namespace}.{nameof(LogError2)}.log"; try { var testedFileLogger = new FileLoggerBase(myPath); var expected = new Exception("test"); testedFileLogger.LogError(expected); var received = File.ReadAllText(myPath); Assert.True(File.Exists(myPath)); Assert.Contains(expected.Message, received); Assert.Contains(MessageSeverity.Error.ToString(), received); } finally { File.Delete(myPath); } }