public void Logging_Test() { const int messagesToLog = 100; const int expectedCount = messagesToLog * 14; const int maxMemoryLoggerEntries = expectedCount / 2; TestEndpoint testEndpoint = new TestEndpoint(); MemoryLogger memoryLogger = new MemoryLogger(); TestUtils.TestForError <ArgumentOutOfRangeException>( () => memoryLogger.MaxNumEntries = -1, "Should not allow a negative value for MaxNumEntries."); memoryLogger.MaxNumEntries = maxMemoryLoggerEntries; using (ConsoleLogger consoleLogger = new ConsoleLogger()) using (TextLogger textLogger = new TextLogger()) using (LogService logger = new LogService()) { textLogger.MaxLogFileEntries = maxMemoryLoggerEntries; logger.RegisterEndpoint(testEndpoint); logger.RegisterEndpoint(consoleLogger); logger.RegisterEndpoint(new DebugTraceLogger()); logger.RegisterEndpoint(memoryLogger); logger.RegisterEndpoint(textLogger); logger.AddFeature("Test Feature"); logger.AddFeature("Test Feature2"); logger.RemoveFeature("Test Feature2"); ConsoleLogger removeLogger = new ConsoleLogger(); logger.RegisterEndpoint(removeLogger); logger.UnregisterEndpoint(removeLogger); logger.RegisterInternalEndpoint(removeLogger); logger.UnregisterInternalEndpoint(removeLogger); logger.RegisterEndpoint( new TextLogger( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TestLogs"), "TestLogs_")); for (int i = 0; i < messagesToLog; i++) { logger.LogInfo($"Test info message {i}"); logger.LogInfo("Test Feature", $"Test feature info message {i}"); logger.LogDebug($"Test debug message {i}"); logger.LogDebug("Test Feature", $"Test feature debug message {i}"); logger.LogVerbose($"Test verbose message {i}"); logger.LogVerbose("Test Feature", $"Test feature verbose message {i}"); logger.LogStatus($"Test status message {i}"); logger.LogStatus("Test Feature", $"Test feature status message {i}"); logger.LogWarning($"Test warning message {i}"); logger.LogWarning("Test Feature", $"Test feature warning message {i}"); logger.LogCritical($"Test critical message {i}"); logger.LogCritical("Test Feature", $"Test feature critical message {i}"); logger.LogFatal($"Test fatal message {i}"); logger.LogFatal("Test Feature", $"Test feature fatal message {i}"); } logger.SignalShutDown(TimeSpan.FromSeconds(5)); logger.SignalShutDown(); } Assert.AreEqual(expectedCount, testEndpoint.NumMessagesLogged); Assert.AreEqual(maxMemoryLoggerEntries, memoryLogger.Entries.Count); }