public void LogFileFinderValidFilesAreOnlyReadOnce() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); var stats = new ApplicationLogsReader.LogFileAccessStats(); var env = new ApplicationLogsTestEnvironment(); var fileFinder = new ApplicationLogsReader.LogFileFinder(env, Mock.Of <ITracer>(), stats); fileFinder.FindLogFiles(); fs.AddLogFile("log-2.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log"); fileFinder.FindLogFiles(); fs.AddLogFile("log-3.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log"); var results = fileFinder.FindLogFiles().ToList(); Assert.Equal(3, results.Count); Assert.Equal(1, stats.GetOpenTextCount("log-1.txt")); Assert.Equal(1, stats.GetOpenTextCount("log-2.txt")); Assert.Equal(1, stats.GetOpenTextCount("log-3.txt")); }
public void LogFileFinderFilesAreNotTrackedOnceDeleted() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); fs.AddLogFile("log-2.txt", @"2014-01-09T00:18:30 System.ApplicationException: The trace listener AzureTableTraceListener is disabled. at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureTableTraceListener.GetCloudTableClientFromEnvironment() at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureTableTraceListener.RefreshConfig() --- End of inner exception stack trace ---" ); var env = new ApplicationLogsTestEnvironment(); var fileFinder = new ApplicationLogsReader.LogFileFinder(env, Mock.Of <ITracer>()); fileFinder.FindLogFiles(); Assert.Equal(1, fileFinder.IncludedFiles.Count); Assert.Equal(1, fileFinder.ExcludedFiles.Count); fs.RemoveLogFile("log-1.txt"); fs.RemoveLogFile("log-2.txt"); fileFinder.FindLogFiles(); Assert.Equal(0, fileFinder.IncludedFiles.Count); Assert.Equal(0, fileFinder.ExcludedFiles.Count); }
public void ApplicationLogsReaderMergesResultsFromMultipleLogFiles() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); fs.AddLogFile("log-2.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); var env = new ApplicationLogsTestEnvironment(); var reader = new ApplicationLogsReader(env, Mock.Of <ITracer>()); var results = reader.GetRecentLogs(6).ToList(); Assert.Equal(6, results.Count); results[0].AssertLogEntry("2013-12-06T00:29:22+00:00", "Error", "this is an error"); results[1].AssertLogEntry("2013-12-06T00:29:22+00:00", "Error", "this is an error"); results[2].AssertLogEntry("2013-12-06T00:29:21+00:00", "Warning", "this is a warning"); results[3].AssertLogEntry("2013-12-06T00:29:21+00:00", "Warning", "this is a warning"); results[4].AssertLogEntry("2013-12-06T00:29:20+00:00", "Information", "this is a log"); results[5].AssertLogEntry("2013-12-06T00:29:20+00:00", "Information", "this is a log"); }
public void LogFileFinderIgnoredFilesAreOnlyReadOnce() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("logging-errors.txt", @"2014-01-09T00:18:30 System.ApplicationException: The trace listener AzureTableTraceListener is disabled. at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureTableTraceListener.GetCloudTableClientFromEnvironment() at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureTableTraceListener.RefreshConfig() --- End of inner exception stack trace ---" ); var stats = new ApplicationLogsReader.LogFileAccessStats(); var env = new ApplicationLogsTestEnvironment(); var fileFinder = new ApplicationLogsReader.LogFileFinder(env, Mock.Of <ITracer>(), stats); var results = fileFinder.FindLogFiles().ToList(); Assert.Equal(0, results.Count); Assert.Equal(1, stats.GetOpenTextCount("logging-errors.txt")); results = fileFinder.FindLogFiles().ToList(); Assert.Equal(0, results.Count); Assert.Equal(1, stats.GetOpenTextCount("logging-errors.txt")); }
public void ResumableLogReaderSeveralSmallBatchesAreEquivalentToOneLargeBatchInTheCaseOfSingleLogFile() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; var logFile = fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); using (var reader = new ApplicationLogsReader.ResumableLogFileReader(logFile, Mock.Of <ITracer>())) using (var reader2 = new ApplicationLogsReader.ResumableLogFileReader(logFile, Mock.Of <ITracer>())) { var result1 = reader.ReadNextBatch(3).ToList(); var result2 = reader2.ReadNextBatch(1) .Concat(reader2.ReadNextBatch(1)) .Concat(reader2.ReadNextBatch(1)) .ToList(); Assert.Equal(reader.LastTime, reader2.LastTime); Assert.Equal(3, result1.Count); Assert.Equal(3, result2.Count); Assert.Equal(result1[0].TimeStamp, result2[0].TimeStamp); Assert.Equal(result1[1].TimeStamp, result2[1].TimeStamp); Assert.Equal(result1[2].TimeStamp, result2[2].TimeStamp); } }
public void ApplicationLogsReaderStartsWithMostRecentlyWrittenFile() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is the most recent log", DateTimeOffset.Parse("2013-12-06T00:29:22+00:00") ); fs.AddLogFile("log-2.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log", DateTimeOffset.Parse("2013-12-06T00:29:20+00:00") ); var env = new ApplicationLogsTestEnvironment(); var reader = new ApplicationLogsReader(env, Mock.Of <ITracer>()); var results = reader.GetRecentLogs(1).ToList(); Assert.Equal(1, results.Count); results[0].AssertLogEntry("2013-12-06T00:29:20+00:00", "Information", "this is the most recent log"); }
public void LogFileFinderEmptyFilesAreReadEachTime() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", ""); var stats = new ApplicationLogsReader.LogFileAccessStats(); var env = new ApplicationLogsTestEnvironment(); var fileFinder = new ApplicationLogsReader.LogFileFinder(env, Mock.Of <ITracer>(), stats); fileFinder.FindLogFiles(); fileFinder.FindLogFiles(); Assert.Equal(2, stats.GetOpenTextCount("log-1.txt")); }
public void LogFileFinderEmptyFilesAreNotReturned() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", ""); var env = new ApplicationLogsTestEnvironment(); var fileFinder = new ApplicationLogsReader.LogFileFinder(env, Mock.Of <ITracer>()); var results = fileFinder.FindLogFiles(); Assert.Equal(0, results.Count()); Assert.Equal(0, fileFinder.IncludedFiles.Count); Assert.Equal(0, fileFinder.ExcludedFiles.Count); }
public void LogFileFinderFindsSingleLogFile() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); var env = new ApplicationLogsTestEnvironment(); var fileFinder = new ApplicationLogsReader.LogFileFinder(env, Mock.Of <ITracer>()); var results = fileFinder.FindLogFiles().ToList(); Assert.Equal(1, results.Count); Assert.Equal(1, fileFinder.IncludedFiles.Count); }
public void ResumableLogReaderLastTimeIsSetToTimeOfLastReadLogEntry() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; var logFile = fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); using (var reader = new ApplicationLogsReader.ResumableLogFileReader(logFile, Mock.Of <ITracer>())) { reader.ReadNextBatch(2); Assert.Equal(DateTimeOffset.Parse("2013-12-06T00:29:21+00:00"), reader.LastTime); } }
public void ApplicationLogsReaderMissingLogMessageIsValidEntry() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:21 PID[20108] Warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); var env = new ApplicationLogsTestEnvironment(); var reader = new ApplicationLogsReader(env, Mock.Of <ITracer>()); var results = reader.GetRecentLogs(6).ToList(); Assert.Equal(4, results.Count); results[1].AssertLogEntry("2013-12-06T00:29:21+00:00", "Warning", ""); }
public void ResumableLogReaderMultilineMessagesAreMergedIntoOneEntry() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; var logFile = fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning that spans several lines 2013-12-06T00:29:22 PID[20108] Error this is an error" ); using (var reader = new ApplicationLogsReader.ResumableLogFileReader(logFile, Mock.Of <ITracer>())) { var results = reader.ReadNextBatch(3); Assert.Equal(3, results.Count); results[1].AssertLogEntry("2013-12-06T00:29:21+00:00", "Warning", "this is a warning\r\nthat spans\r\nseveral lines"); } }
public void ResumableLogReaderLogEntriesAreReturnedInReverseOrder() { var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; var logFile = fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:22 PID[20108] Error this is an error" ); using (var reader = new ApplicationLogsReader.ResumableLogFileReader(logFile, Mock.Of <ITracer>())) { var entry1 = reader.ReadNextBatch(1).Single(); var entry2 = reader.ReadNextBatch(1).Single(); var entry3 = reader.ReadNextBatch(1).Single(); entry1.AssertLogEntry("2013-12-06T00:29:22+00:00", "Error", "this is an error"); entry2.AssertLogEntry("2013-12-06T00:29:21+00:00", "Warning", "this is a warning"); entry3.AssertLogEntry("2013-12-06T00:29:20+00:00", "Information", "this is a log"); } }
public void ApplicationLogsReaderIncompleteLogEntryIsTreatedAsContentsOfLastValidEntry() { // This is really just a variation on the multiline tests but is here to demonstrate that any 'junk' lines // will just be treated as part of the preceeding log message var fs = new ApplicationLogsTestFileSystem(); FileSystemHelpers.Instance = fs; fs.AddLogFile("log-1.txt", @"2013-12-06T00:29:20 PID[20108] Information this is a log 2013-12-06T00:29:21 PID[20108] Warning this is a warning 2013-12-06T00:29:21 PID[20108] 2013-12-06T00:29:22 PID[20108] Error this is an error" ); var env = new ApplicationLogsTestEnvironment(); var reader = new ApplicationLogsReader(env, Mock.Of <ITracer>()); var results = reader.GetRecentLogs(6).ToList(); Assert.Equal(3, results.Count); }