protected override ParsingResult ParseSource(ILogSource source, LogReaderSettings settings, ParsingResult result = null) { if (source == null) { throw new ArgumentNullException(nameof(source)); } TextStorage storage = new TextStorage(); result = result ?? new ParsingResult(); var log = (IEnumerable <string[]>)source; if (!(source is AzureLogSource)) { throw new ApplicationException("Non Azure log source was tried to be parsed by Azure log reader"); } foreach (var lines in log) { var logEntry = logParser.ParseLine(lines[0], new DateTime(long.Parse(lines[1])), storage); if (logEntry != null) { logEntry = AnalyzeLog(logEntry, storage); result.AddToGroupAll(logEntry); } } return(result); }
public JobModule(LogReaderSettings settings, IReloadingManager <DbSettings> dbSettingsManager, ILog log) { _settings = settings; _log = log; _dbSettingsManager = dbSettingsManager; _services = new ServiceCollection(); }
public override ParsingResult ParseLogs(ILogSource source, LogReaderSettings settings) { if (AzureSourceStateStorage.ParsingResultWithoutFiltering == null) AzureSourceStateStorage.ParsingResultWithoutFiltering = base.ParseLogs(source, null); ParsingResult result = FilterLogs(AzureSourceStateStorage.ParsingResultWithoutFiltering, settings); return ReorginizeParsingResult(result); }
public override ParsingResult ParseLogs(ILogSource source, LogReaderSettings settings) { if (AzureSourceStateStorage.ParsingResultWithoutFiltering == null) { AzureSourceStateStorage.ParsingResultWithoutFiltering = base.ParseLogs(source, null); } ParsingResult result = FilterLogs(AzureSourceStateStorage.ParsingResultWithoutFiltering, settings); return(ReorginizeParsingResult(result)); }
private ParsingResult FilterLogs(ParsingResult parsingResultWithoutFiltering, LogReaderSettings settings) { ParsingResult parsingResult = new ParsingResult(); foreach (var entry in parsingResultWithoutFiltering.All) { bool matchesFilter = false; ApplyFilter(entry.LogDateTime, settings, entry.ToString(), ref matchesFilter, false); if (matchesFilter) parsingResult.AddToGroupAll(entry); } return parsingResult; }
protected override ParsingResult ParseSource(ILogSource source, LogReaderSettings settings, ParsingResult result = null) { if (source == null) throw new ArgumentNullException(nameof(source)); TextStorage storage = new TextStorage(); result = result ?? new ParsingResult(); var log = (IEnumerable<string[]>)source; if (!(source is AzureLogSource)) throw new ApplicationException("Non Azure log source was tried to be parsed by Azure log reader"); foreach (var lines in log) { var logEntry = logParser.ParseLine(lines[0], new DateTime(long.Parse(lines[1])), storage); if (logEntry != null) { logEntry = AnalyzeLog(logEntry, storage); result.AddToGroupAll(logEntry); } } return result; }
public static HealthcheckResult RunHealthcheck(string fileNameFormat, string directoryPath, DateTime itemCreationDate, int numberDaysToCheck, bool isRemote = false) { var checkResult = new HealthcheckResult { LastCheckTime = DateTime.UtcNow, Status = Customization.HealthcheckStatus.Healthy, HealthyMessage = "There is no new error since the last check", ErrorList = new ErrorList { Entries = new List <ErrorEntry>() } }; if (string.IsNullOrEmpty(fileNameFormat)) { checkResult.Status = Customization.HealthcheckStatus.Warning; checkResult.ErrorList.Entries.Add(new ErrorEntry { Created = DateTime.UtcNow, Reason = "Log File Check is not configured correctly", Exception = null }); return(checkResult); } try { var directory = GetLogFileDirectory(directoryPath); var files = directory.GetFiles(fileNameFormat); if (files == null || files.Count() == 0) { checkResult.Status = HealthcheckStatus.Warning; checkResult.ErrorList.Entries.Add(new ErrorEntry { Created = DateTime.UtcNow, Reason = string.Format("No files can be found with the following pattern: {0}", fileNameFormat), Exception = null }); return(checkResult); } LogReaderSettings logReaderSettings = new LogReaderSettings(itemCreationDate, DateTime.MaxValue); if (numberDaysToCheck > 0) { if (isRemote) { logReaderSettings.StartDateTime = itemCreationDate.ToLocalTime(); } else { logReaderSettings.StartDateTime = DateTime.Now.AddDays(-numberDaysToCheck).Date; } logReaderSettings.FinishDateTime = DateTime.Now; } LogDataSource logDataSource = new LogDataSource(files, logReaderSettings); logDataSource.ParseFiles(); var result = logDataSource.LogData; if (result.Errors != null && result.Errors.Count > 0) { checkResult.Status = HealthcheckStatus.Error; foreach (var error in result.Errors) { checkResult.ErrorList.Entries.Add(new ErrorEntry { Created = error.Time, Reason = error.Message?.Message, Exception = null }); } } else if (result.Warns != null && result.Warns.Count > 0) { checkResult.Status = HealthcheckStatus.Warning; foreach (var warn in result.Warns) { checkResult.ErrorList.Entries.Add(new ErrorEntry { Created = warn.Time, Reason = warn.Message?.Message, Exception = null }); } } } catch (Exception exception) { checkResult.Status = HealthcheckStatus.Error; checkResult.ErrorList.Entries.Add(new ErrorEntry { Created = DateTime.UtcNow, Reason = exception.Message, Exception = exception }); } return(checkResult); }
private ParsingResult FilterLogs(ParsingResult parsingResultWithoutFiltering, LogReaderSettings settings) { ParsingResult parsingResult = new ParsingResult(); foreach (var entry in parsingResultWithoutFiltering.All) { bool matchesFilter = false; ApplyFilter(entry.LogDateTime, settings, entry.ToString(), ref matchesFilter, false); if (matchesFilter) { parsingResult.AddToGroupAll(entry); } } return(parsingResult); }