public static void ReadConfiguration() { string fileLocation = "d:\\MessageTracingServiceLogs"; ServiceLogger.ServiceLogLevel = ServiceLogger.LogLevel.Error; ServiceLogger.MaximumLogAge = TimeSpan.Parse("5.00:00:00"); ServiceLogger.MaximumLogDirectorySize = 500000000L; ServiceLogger.MaximumLogFileSize = 5000000L; try { fileLocation = ConfigurationManager.AppSettings["LogFilePath"].Trim(); ServiceLogger.ServiceLogLevel = (ServiceLogger.LogLevel)Convert.ToInt32(ConfigurationManager.AppSettings["LogLevel"]); ServiceLogger.MaximumLogAge = TimeSpan.Parse(ConfigurationManager.AppSettings["LogFileMaximumLogAge"]); ServiceLogger.MaximumLogDirectorySize = Convert.ToInt64(ConfigurationManager.AppSettings["LogFileMaximumLogDirectorySize"]); ServiceLogger.MaximumLogFileSize = Convert.ToInt64(ConfigurationManager.AppSettings["LogFileMaximumLogFileSize"]); } catch (Exception ex) { string text = string.Format("Fail to read config value, default values are used. The error is {0}", ex.ToString()); EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_ConfigSettingNotFound, Thread.CurrentThread.Name, new object[] { text }); EventNotificationItem.Publish(ExchangeComponent.Name, "BadServiceLoggerConfig", null, text, ResultSeverityLevel.Error, false); if (RetryHelper.IsSystemFatal(ex)) { throw; } } finally { ServiceLogger.FileLocation = fileLocation; } }
private string BuildWatermarkFileInfo(ILogFileInfo logFileInfo) { string watermarkFileFullName = logFileInfo.WatermarkFileObj.WatermarkFileFullName; string result = string.Empty; try { FileInfo fileInfo = new FileInfo(watermarkFileFullName); if (fileInfo.Exists) { result = string.Format("the watermark file={0},created={1},modified={2}", watermarkFileFullName, fileInfo.CreationTimeUtc, fileInfo.LastWriteTimeUtc); } else { result = string.Format("the watermark file {0} doesn't exist", watermarkFileFullName); } } catch (Exception ex) { if (RetryHelper.IsSystemFatal(ex)) { throw; } result = string.Format("the watermark file {0} exists but can't retrive its info because of exception: {1}", watermarkFileFullName, ex.Message); } return(result); }
private static void InvokeOnce(ref int retryCount, int maxRetryCount, TimeSpan slowResponseTime, TimeSpan sleepInterval, Action action, Predicate <Exception> isRetriableException, Predicate <Exception> isDataStoreUnavailableException, Action <Exception, int> onRetry, Action <Exception, int> onMaxRetry, Action <TimeSpan> onSlowResponse, out bool needsRetry) { needsRetry = false; try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); action(); stopwatch.Stop(); if (stopwatch.Elapsed > slowResponseTime) { onSlowResponse(stopwatch.Elapsed); } } catch (Exception ex) { if (RetryHelper.IsSystemFatal(ex) || RetryHelper.IsFatalDefect(ex)) { throw; } if (ex is TransientDALException || ex is PermanentDALException) { throw; } if (!isRetriableException(ex)) { throw new PermanentDALException(Strings.ErrorPermanentDALException, ex); } if (Transaction.Current != null) { throw new TransientDALException(Strings.ErrorTransientDALExceptionAmbientTransaction, ex); } if (retryCount >= maxRetryCount) { onMaxRetry(ex, maxRetryCount); if (isDataStoreUnavailableException(ex)) { throw new TransientDataProviderUnavailableException(Strings.ErrorDataStoreUnavailable, ex); } throw new TransientDALException(Strings.ErrorTransientDALExceptionMaxRetries, ex); } else { retryCount++; onRetry(ex, retryCount); Thread.Sleep(sleepInterval); needsRetry = true; } } }
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); }
internal void ProcessBlock(CsvFieldCache cursor, LogFileRange block, LogFileInfo log) { bool flag = false; if (cursor.Position < block.StartOffset) { cursor.Seek(block.StartOffset); } long num = cursor.Position; while (cursor.Position < block.EndOffset) { if (this.CheckServiceStopRequest("ProcessBlock()")) { return; } try { flag = cursor.MoveNext(true); if (!flag) { if (cursor.AtEnd && !log.IsActive) { this.inputBuffer.AddInvalidRowToSkip(num, cursor.Position); block.EndOffset = cursor.Position; num = cursor.Position; } break; } ReadOnlyRow readOnlyRow = new ReadOnlyRow(cursor, num); this.inputBuffer.LineReceived(readOnlyRow); num = readOnlyRow.EndPosition; } catch (Exception ex) { if (RetryHelper.IsSystemFatal(ex)) { throw; } string text = string.Format("Log={0} blockRange=({1},{2}) cursorOffset={3} rowEnd={4} logSize={5} \nException:{6}", new object[] { log.FullFileName, block.StartOffset, block.EndOffset, cursor.Position, num, log.Size, ex }); string periodicKey = string.Format("{0}_{1}_{2}", log.FileName, block.StartOffset, block.EndOffset); EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_CsvParserFailedToParseLogLine, periodicKey, new object[] { text }); ServiceLogger.LogError(ServiceLogger.Component.LogReader, (LogUploaderEventLogConstants.Message) 3221229487U, string.Format("Detail={0}", text), this.instance, log.FullFileName); flag = false; break; } } if (cursor.Position == block.EndOffset) { block.ProcessingStatus = ProcessingStatus.ReadyToWriteToDatabase; } if (!flag) { if (cursor.AtEnd) { if (block.EndOffset == 9223372036854775807L) { block.EndOffset = cursor.Position; } } else if (this.logHeaderEndOffset != block.EndOffset) { string text2 = string.Format("Failed to read line from file {0} at position {1}", log.FullFileName, num); ExTraceGlobals.ReaderTracer.TraceError((long)this.GetHashCode(), text2); EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_LogReaderReadFailed, log.FullFileName + "_" + num.ToString(), new object[] { log.FullFileName, num }); ServiceLogger.LogError(ServiceLogger.Component.LogReader, (LogUploaderEventLogConstants.Message) 3221229476U, text2, this.instance, log.FullFileName); } } long incrementValue = num - block.StartOffset; if (Tools.IsRawProcessingType <T>()) { this.perfCounterInstance.RawReaderParsedBytes.IncrementBy(incrementValue); } else { this.perfCounterInstance.ReaderParsedBytes.IncrementBy(incrementValue); } log.WatermarkFileObj.UpdateLastReaderParsedEndOffset(num); }