public void AppendTest() { var myPath = $"{typeof(JsonFileLoggerTest).Namespace}.{nameof(AppendTest)}.json"; try { var testedFileLogger = new JsonFileLogger(myPath); var expectedError1 = new Exception("test1"); var expectedError2 = "test2"; var expectedWarning = "test3"; var expectedinfo = "test4"; 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 LogError1() { var myPath = $"{typeof(JsonFileLoggerTest).Namespace}.{nameof(LogError1)}.json"; try { var testedFileLogger = new JsonFileLogger(myPath); var expected = "test"; testedFileLogger.LogError(expected); var received = File.ReadAllText(myPath); Assert.True(File.Exists(myPath)); Assert.Contains(expected, received); Assert.Contains(MessageSeverity.Error.ToString(), received); } finally { File.Delete(myPath); } }