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 JsonLoggerCreate() { var myPath = $"{typeof(JsonFileLoggerTest).Namespace}.{nameof(JsonLoggerCreate)}.json"; try { var tested = new JsonFileLogger(); var testedFileLogger = new JsonFileLogger(myPath); testedFileLogger.LogInfo("test70113"); Assert.True(File.Exists(myPath)); Assert.Equal(".json", Path.GetExtension(testedFileLogger.OutputFile.Name)); } finally { File.Delete(myPath); } }
private static void Main(string[] args) { Console.WriteLine("Hello in JSON logger test harness! " + "This is the load test. The file logger will be spammed with the number of messages (random GUIDs) you choose from multiple threads."); Console.Write("Please enter number of messages to spam with: "); var validInteger = GetNaturalInt(); if (validInteger > 100000) { Console.Write(" This can take a while:)"); } Console.WriteLine(); var file = new FileInfo(Path.ChangeExtension(Path.GetRandomFileName(), "json")); Console.WriteLine($"The contents will be written to {file.FullName}."); var fileLogger = new JsonFileLogger(file.FullName); var watch = Stopwatch.StartNew(); Parallel.For(0, validInteger, x => { fileLogger.LogInfo(Guid.NewGuid().ToString()); }); watch.Stop(); Console.WriteLine($"Finished in {watch.Elapsed}");// with {wrapper.FailedDequeues} failures, after {wrapper.LogRequests} log requests"); Console.WriteLine("Open file? y/n"); var key = Console.ReadKey(); if (key.KeyChar == 'y') { using (var process = Process.Start(new ProcessStartInfo { FileName = fileLogger.OutputFile.FullName, UseShellExecute = true })) { } } Console.WriteLine(); Console.WriteLine("Delete file? y/n"); key = Console.ReadKey(); if (key.KeyChar == 'y') { fileLogger.OutputFile.Delete(); } }
public void LogInfo() { var myPath = $"{typeof(JsonFileLoggerTest).Namespace}.{nameof(LogInfo)}.json"; try { var testedFileLogger = new JsonFileLogger(myPath); var expected = "test"; testedFileLogger.LogInfo(expected); var received = File.ReadAllText(myPath); Assert.True(File.Exists(myPath)); Assert.Contains(expected, received); Assert.Contains(MessageSeverity.Information.ToString(), received); } finally { File.Delete(myPath); } }