Example #1
0
        protected void UpdateStaleLogs(ILogFileInfo logFileInfo)
        {
            double totalHours = DateTime.UtcNow.Subtract(logFileInfo.LastWriteTimeUtc).TotalHours;

            if (!this.IsFileProcessedBefore(logFileInfo) && !LogMonitor <T> .IsEmptyLog(logFileInfo) && totalHours >= this.config.BacklogAlertNonUrgentThreshold.TotalHours)
            {
                this.staleLogs.Add(logFileInfo);
                if (totalHours >= this.config.BacklogAlertUrgentThreshold.TotalHours)
                {
                    this.veryStaleLogs.Add(logFileInfo);
                }
            }
        }
Example #2
0
        private void ReportBacklogCondition(int staleLogCount, int veryStaleLogCount, string logDir, List <ILogFileInfo> logList, bool isUrgent)
        {
            int num = Math.Min(logList.Count, 10);
            IEnumerable <ILogFileInfo> enumerable = logList.Take(num);
            StringBuilder stringBuilder           = new StringBuilder();
            string        value = (num > 1) ? string.Format("The first {0} logs are:", num) : "Here are the detailed info:";

            stringBuilder.AppendLine(value);
            foreach (ILogFileInfo logFileInfo in enumerable)
            {
                string text  = this.BuildWatermarkFileInfo(logFileInfo);
                string text2 = "unknown";
                try
                {
                    FileInfo fileInfo = new FileInfo(logFileInfo.FullFileName);
                    if (fileInfo.Exists)
                    {
                        text2 = string.Format("{0} bytes", fileInfo.Length);
                    }
                }
                catch (Exception ex)
                {
                    if (RetryHelper.IsSystemFatal(ex))
                    {
                        throw;
                    }
                }
                stringBuilder.AppendLine(string.Format("The log file {0} is {1}, its size is {2}, created on {3}, last modified on {4}, {5}", new object[]
                {
                    logFileInfo.FullFileName,
                    logFileInfo.IsActive ? "Active" : "Inactive",
                    text2,
                    logFileInfo.CreationTimeUtc,
                    logFileInfo.LastWriteTimeUtc,
                    text
                }));
            }
            string text3 = string.Format("There are {0} logs in directory {1} that haven't been processed for {2} hours. {3} of them are over {4} hours.\n{5}", new object[]
            {
                staleLogCount,
                logDir,
                this.config.BacklogAlertNonUrgentThreshold.TotalHours,
                veryStaleLogCount,
                this.config.BacklogAlertUrgentThreshold.TotalHours,
                stringBuilder.ToString()
            });

            if (isUrgent)
            {
                LogMonitor <T> .RaiseAlertIfHealthStateChange(ref this.veryStaleLogReportedBefore, "SeriousBacklogBuiltUp", text3);
            }
            else
            {
                LogMonitor <T> .RaiseAlertIfHealthStateChange(ref this.staleLogReportedBefore, "BacklogBuiltUp", text3);
            }
            EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_LogMonitorDetectLogProcessingFallsBehind, this.instance, new object[]
            {
                staleLogCount,
                logDir,
                this.config.BacklogAlertNonUrgentThreshold.TotalHours,
                veryStaleLogCount,
                this.config.BacklogAlertUrgentThreshold.TotalHours,
                stringBuilder.ToString()
            });
            ServiceLogger.LogError(ServiceLogger.Component.LogMonitor, (LogUploaderEventLogConstants.Message) 3221228478U, text3, this.instance, this.logDirectory);
        }