public void RockLogReaderShouldReturnZeroLogEntriesIfNoLogFilesExist() { var config = new RockLogConfiguration { LogLevel = RockLogLevel.All, MaxFileSize = 1, NumberOfLogFiles = 3, DomainsToLog = new List <string> { "OTHER" }, LogPath = $"{LogFolder}\\{Guid.NewGuid()}.log", LastUpdated = DateTime.Now }; var logger = ReflectionHelper.InstantiateInternalObject <IRockLogger>("Rock.Logging.RockLoggerSerilog", config); logger.Information("Test"); logger.Close(); System.IO.File.Delete(config.LogPath); var rockReader = ReflectionHelper.InstantiateInternalObject <IRockLogReader>("Rock.Logging.RockSerilogReader", logger); var currentPageIndex = 0; var pageSize = 1000; var results = rockReader.GetEvents(currentPageIndex, pageSize); Assert.That.AreEqual(0, results.Count); }
public void RockLogReaderShouldHandleDomainCorrectly() { var config = new RockLogConfiguration { LogLevel = RockLogLevel.All, MaxFileSize = 1, NumberOfLogFiles = 3, DomainsToLog = new List <string> { "OTHER" }, LogPath = $"{LogFolder}\\{Guid.NewGuid()}.log", LastUpdated = DateTime.Now }; var logger = ReflectionHelper.InstantiateInternalObject <IRockLogger>("Rock.Logging.RockLoggerSerilog", config); var expectedMessage = "This is a test."; var expectedDomain = RockLogDomains.Other; logger.Information(expectedMessage); var rockReader = ReflectionHelper.InstantiateInternalObject <IRockLogReader>("Rock.Logging.RockSerilogReader", logger); var currentPageIndex = 0; var pageSize = 100; var nextPageIndex = currentPageIndex + pageSize; var results = rockReader.GetEvents(currentPageIndex, pageSize); Assert.That.AreEqual(1, results.Count); Assert.That.AreEqual(expectedMessage, results[0].Message); Assert.That.AreEqual(expectedDomain, results[0].Domain); }
public void RockLogReaderShouldReturnAllResultsWithMaxPlusOnePageSize() { var config = new RockLogConfiguration { LogLevel = RockLogLevel.All, MaxFileSize = 1, NumberOfLogFiles = 3, DomainsToLog = new List <string> { "OTHER" }, LogPath = $"{LogFolder}\\{Guid.NewGuid()}.log", LastUpdated = DateTime.Now }; var logger = ReflectionHelper.InstantiateInternalObject <IRockLogger>("Rock.Logging.RockLoggerSerilog", config); var expectedLogs = CreateLogFiles(logger); var rockReader = ReflectionHelper.InstantiateInternalObject <IRockLogReader>("Rock.Logging.RockSerilogReader", logger); var currentPageIndex = 0; var pageSize = 19000; var nextPageIndex = currentPageIndex + pageSize; var results = rockReader.GetEvents(currentPageIndex, pageSize); Assert.That.AreEqual(expectedLogs.Count, results.Count); }
private IRockLogger GetTestLogger(string logFolder = "", List <string> domainsToLog = null, RockLogLevel logLevel = RockLogLevel.All, int numberOfLogFiles = 2, int logSize = 1) { if (string.IsNullOrWhiteSpace(logFolder)) { logFolder = LogFolder; } if (domainsToLog == null) { domainsToLog = new List <string> { "OTHER", "crm" }; } var config = new RockLogConfiguration { LogLevel = logLevel, MaxFileSize = logSize, NumberOfLogFiles = numberOfLogFiles, DomainsToLog = domainsToLog, LogPath = $"{logFolder}\\{Guid.NewGuid()}.log", LastUpdated = RockDateTime.Now }; return(ReflectionHelper.InstantiateInternalObject <IRockLogger>("Rock.Logging.RockLoggerSerilog", config)); }
public void RockLogReaderShouldReturnLogEntriesInCorrectOrder() { var config = new RockLogConfiguration { LogLevel = RockLogLevel.All, MaxFileSize = 1, NumberOfLogFiles = 3, DomainsToLog = new List <string> { "OTHER" }, LogPath = $"{LogFolder}\\{Guid.NewGuid()}.log", LastUpdated = DateTime.Now }; var logger = ReflectionHelper.InstantiateInternalObject <IRockLogger>("Rock.Logging.RockLoggerSerilog", config); var expectedLogs = CreateLogFiles(logger); var rockReader = ReflectionHelper.InstantiateInternalObject <IRockLogReader>("Rock.Logging.RockSerilogReader", logger); var currentPageIndex = 0; var pageSize = 1000; var nextPageIndex = currentPageIndex + pageSize; var results = rockReader.GetEvents(currentPageIndex, pageSize); var lastIndex = expectedLogs.Count - 1; for (var i = lastIndex; i >= 0; i--) { if ((lastIndex - i) >= nextPageIndex) { currentPageIndex = nextPageIndex; nextPageIndex = currentPageIndex + pageSize; results = rockReader.GetEvents(currentPageIndex, pageSize); } var resultIndex = lastIndex - i - currentPageIndex; Assert.That.Contains(results[resultIndex].Message, expectedLogs[i]); } }
public void RockLogReaderShouldReturnCorrectRecordCount() { var config = new RockLogConfiguration { LogLevel = RockLogLevel.All, MaxFileSize = 1, NumberOfLogFiles = 3, DomainsToLog = new List <string> { "OTHER" }, LogPath = $"{LogFolder}\\{Guid.NewGuid()}.log", LastUpdated = RockDateTime.Now }; var logger = ReflectionHelper.InstantiateInternalObject <IRockLogger>("Rock.Logging.RockLoggerSerilog", config); var expectedLogs = CreateLogFiles(logger); var rockReader = ReflectionHelper.InstantiateInternalObject <IRockLogReader>("Rock.Logging.RockSerilogReader", logger); Assert.That.AreEqual(expectedLogs.Count, rockReader.RecordCount); }
public RockLoggerSerilogTests() { ObjectToLog = GetTestObjectToSerialize(); }