Esempio n. 1
0
        /// <summary>
        /// Check if the current line is within the time window and save it to a blockingCollection
        /// </summary>
        /// <param name="line">current log line</param>
        private void RemoveLineFromLogFile(string line)
        {
            // If Match, we ignore the line
            Match m = Regex.Match(line, LineRegex);

            if (!m.Success)
            {
                ExtractedLines.Add(line);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Process the log lines multi threaded if possible
        /// </summary>
        /// <param name="cancellationToken">Cancels the process</param>
        private void ProcessLines(CancellationToken cancellationToken)
        {
            Parallel.ForEach(
                _tempLines.GetConsumingEnumerable().AsParallel().AsOrdered(),
                (line, loopState) =>
            {
                switch (ExtractionType)
                {
                case ExtractionType.RemoveLines:
                    RemoveLineFromLogFile(line);
                    break;

                case ExtractionType.ExtractLines:
                    ExtractLineFromLogFile(line);
                    break;

                case ExtractionType.ObfuscateLines:
                    ObfuscateLine(line);
                    break;

                default:
                    RemoveLineFromLogFile(line);
                    break;
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    loopState.Break();
                }
            });

            if (_tempLines.IsCompleted)
            {
                // TODO ADD Event for completion so user knows
                ExtractedLines.CompleteAdding();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Check if the current line is within the time window and save it to a blockingCollection
        /// </summary>
        /// <param name="line">current log line</param>
        private void ExtractLineFromLogFile(string line)
        {
            Match m = Regex.Match(line, Interval ? TimeFilterRegex : LineRegex);

            if (!m.Success)
            {
                return;
            }

            if (Interval)
            {
                if (DateTimeOffset.TryParse(m.Groups[0].Value.Trim(), out DateTimeOffset parsedTime))
                {
                    if (parsedTime > StartTime && parsedTime < EndTime)
                    {
                        ExtractedLines.Add(line);
                    }
                }
            }
            else
            {
                ExtractedLines.Add(line);
            }
        }