public void InnerExceptionTest() { _loggingService = new LoggingService(); _loggingService.Initialise(1000000); _loggingService.Recycle(); Thread.Sleep(1000);// Ensure unique archive file name! var ex7 = new ApplicationException("Ex_Seventh"); var ex6 = new ApplicationException("Ex_Sixth", ex7); var ex5 = new ApplicationException("Ex_Fifth", ex6); var ex4 = new ApplicationException("Ex_Fourth", ex5); var ex3 = new ApplicationException("Ex_Third", ex4); var ex2 = new ApplicationException("Ex_Second", ex3); var ex1 = new ApplicationException("Ex_First", ex2); _loggingService.Error(ex1); var logs = _loggingService.ListLogFile(); // Only log down to 5 inner exceptions Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_Fifth"))); Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_Fourth"))); Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_Third"))); Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_Second"))); Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_First"))); Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_Sixth"))); Assert.IsFalse(logs.Any(item => item.ErrorMessage.Contains("Ex_Seventh"))); }
public void ExceptionTest() { // Test without inner exceptions _loggingService = new LoggingService(); _loggingService.Initialise(1000000); _loggingService.Recycle(); Thread.Sleep(1000);// Ensure unique archive file name! var ex1 = new ApplicationException("Ex_First"); _loggingService.Error(ex1); var logs = _loggingService.ListLogFile(); Assert.IsTrue(logs.Count == 1); // Only log down to 5 inner exceptions Assert.IsFalse(logs.Any(item => item.ErrorMessage.Contains("INNER EXCEPTION:"))); Assert.IsTrue(logs.Any(item => item.ErrorMessage.Contains("Ex_First"))); }
public void RecycleTest() { // Test that the file recycles // Set the size _loggingService = new LoggingService(); _loggingService.Initialise(114); // Allows two lines _loggingService.Recycle(); Thread.Sleep(1000);// Ensure unique archive file name! // Each line looks like this: "01/10/2012 13:49:01 | mscorlib.dll | InvokeMethod | 9ABC" _loggingService.Error("1234"); _loggingService.Error("5678"); // At this point have two lines before recycling var logs = _loggingService.ListLogFile(); Assert.IsTrue(logs.Count == 2); // Add another line - will tip over the recycling point _loggingService.Error("9ABC"); logs = _loggingService.ListLogFile(); Assert.IsTrue(logs.Count == 1); }