Example #1
0
        internal void ReadLog()
        {
            LogFileInfo logFileInfo = null;
            int         num         = 0;

            try
            {
                if (this.batchQueue.IsFull)
                {
                    num = Tools.RandomizeTimeSpan(this.config.ReaderSleepTime, this.config.ReaderSleepTimeRandomRange);
                    string text = string.Format("The queue for log prefix {0} is full. Reader will not parse it until the queue is no longer full.", this.instance);
                    ExTraceGlobals.ReaderTracer.TraceWarning((long)this.GetHashCode(), text);
                    EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_LogReaderQueueFull, this.instance, new object[]
                    {
                        this.instance
                    });
                    long num2 = DateTime.UtcNow.Ticks - this.lastTimeWhenQeueFull;
                    if (num2 > 1800000000L)
                    {
                        this.lastTimeWhenQeueFull = DateTime.UtcNow.Ticks;
                        ServiceLogger.LogWarning(ServiceLogger.Component.LogReader, (LogUploaderEventLogConstants.Message) 2147487654U, text, this.instance, "");
                    }
                }
                else
                {
                    logFileInfo = this.logMonitor.GetLogForReaderToProcess();
                    if (logFileInfo == null)
                    {
                        num = Tools.RandomizeTimeSpan(this.config.ReaderSleepTime, this.config.ReaderSleepTimeRandomRange);
                    }
                    else
                    {
                        this.ProcessLog(logFileInfo);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_LogReaderLogMissing, ex.Message, new object[]
                {
                    Thread.CurrentThread.Name,
                    ex
                });
                ServiceLogger.LogError(ServiceLogger.Component.LogReader, (LogUploaderEventLogConstants.Message) 2147487659U, ex.Message, this.instance, "");
                this.logMonitor.ReaderCompletedProcessingLog(logFileInfo);
                return;
            }
            catch (IOException ex2)
            {
                string text2 = (logFileInfo == null) ? "unknown log" : logFileInfo.FullFileName;
                string text3 = string.Format("Caught an IOException when reading log {0}. Exception: {1}", text2, ex2);
                ExTraceGlobals.LogMonitorTracer.TraceError((long)this.GetHashCode(), text3);
                EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_ReadLogCaughtIOException, logFileInfo.FullFileName, new object[]
                {
                    logFileInfo.FullFileName,
                    ex2
                });
                ServiceLogger.LogError(ServiceLogger.Component.LogReader, (LogUploaderEventLogConstants.Message) 3221229485U, text3, this.instance, text2);
                if (!ex2.Message.Contains("Insufficient system resources exist to complete the requested service"))
                {
                    throw;
                }
                this.logMonitor.ReaderCompletedProcessingLog(logFileInfo);
            }
            catch (NotSupportedException ex3)
            {
                EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_UnsupportedLogVersion, "UnSupportedLogVersion", new object[]
                {
                    logFileInfo.FullFileName,
                    ex3
                });
                ServiceLogger.LogError(ServiceLogger.Component.LogMonitor, (LogUploaderEventLogConstants.Message) 3221229488U, ex3.Message, this.instance, logFileInfo.FullFileName);
                EventNotificationItem.Publish(ExchangeComponent.Name, "UnsupportedLogVersion", null, ex3.Message, ResultSeverityLevel.Error, false);
                throw ex3;
            }
            catch (Exception ex4)
            {
                if (!(ex4 is ThreadAbortException) || !this.cancellationContext.StopToken.IsCancellationRequested)
                {
                    string text4 = (logFileInfo == null) ? "unknown log" : logFileInfo.FullFileName;
                    string text5 = string.Format("{0} processing {1} catches an exception: {2}", Thread.CurrentThread.Name, text4, ex4);
                    ExTraceGlobals.ReaderTracer.TraceError((long)this.GetHashCode(), text5);
                    EventLogger.Logger.LogEvent(LogUploaderEventLogConstants.Tuple_LogReaderUnknownError, null, new object[]
                    {
                        Thread.CurrentThread.Name,
                        text4,
                        ex4
                    });
                    EventNotificationItem.Publish(ExchangeComponent.Name, "LogReaderUnknownError", null, text5, ResultSeverityLevel.Error, false);
                    this.perfCounterInstance.TotalLogReaderUnknownErrors.Increment();
                    ServiceLogger.LogError(ServiceLogger.Component.LogReader, (LogUploaderEventLogConstants.Message) 3221229474U, text5, this.instance, text4);
                    throw;
                }
                Thread.ResetAbort();
                ServiceLogger.LogInfo(ServiceLogger.Component.DatabaseWriter, LogUploaderEventLogConstants.Message.LogMonitorRequestedStop, Thread.CurrentThread.Name + " received thread abort event", this.instance, "");
            }
            if (num > 0 && this.cancellationContext.StopToken.WaitHandle.WaitOne(num))
            {
                this.cancellationContext.StopWaitHandle.Set();
            }
        }