private ProcessLogTypeResult ProcessDir(LogSetInfo logSetInfo, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var processingStatistics = new ProcessLogTypeResult();

            foreach (var filePath in Directory.EnumerateFiles(logSetInfo.Path, "*", SearchOption.AllDirectories))
            {
                var normalizedPath = filePath.NormalizePath(logSetInfo.Path);
                if (!logTypeInfo.FileBelongsToThisType(normalizedPath))
                {
                    continue;
                }

                _logger.LogInformation("Processing file {}", normalizedPath);
                var fileSizeBytes     = new FileInfo(filePath).Length;
                var fileTimer         = Stopwatch.StartNew();
                var processFileResult = ProcessFile(filePath, normalizedPath, logTypeInfo, plugins);
                processingStatistics.AddProcessingInfo(fileTimer.Elapsed, fileSizeBytes, processFileResult);

                if (!processFileResult.IsSuccessful)
                {
                    break;
                }

                LogFileProcessingResults(normalizedPath, fileSizeBytes, processFileResult, fileTimer.Elapsed);
            }

            return(processingStatistics);
        }
        private ProcessLogTypeResult ProcessZip(LogSetInfo logSetInfo, LogTypeInfo logTypeInfo, IList <IPlugin> plugins)
        {
            var processingStatistics = new ProcessLogTypeResult();

            using var zip = ZipFile.Open(logSetInfo.Path, ZipArchiveMode.Read);
            foreach (var fileEntry in zip.Entries)
            {
                if (!logTypeInfo.FileBelongsToThisType(fileEntry.FullName))
                {
                    continue;
                }

                var fileNameWithPrefix = string.IsNullOrWhiteSpace(logSetInfo.Prefix)
                    ? fileEntry.FullName
                    : $"{logSetInfo.Prefix}/{fileEntry.FullName}";

                _logger.LogInformation("Processing file {logFile}", fileNameWithPrefix);
                var fileTimer         = Stopwatch.StartNew();
                var processFileResult = ProcessZippedFile(fileEntry, fileNameWithPrefix, logTypeInfo, plugins);
                processingStatistics.AddProcessingInfo(fileTimer.Elapsed, fileEntry.Length, processFileResult);

                if (!processFileResult.IsSuccessful)
                {
                    break;
                }

                LogFileProcessingResults(fileNameWithPrefix, fileEntry.Length, processFileResult, fileTimer.Elapsed);
            }

            return(processingStatistics);
        }
Beispiel #3
0
        public void TestSingleLocationInfo(string filename, bool expectedResult)
        {
            var singleLocationInfo = new LogTypeInfo(LogType.Apache, (stream, _) => new SimpleLinePerLineReader(stream), new List <Regex>
            {
                new Regex(@"fileOne\.txt", RegexOptions.Compiled)
            });

            var result = singleLocationInfo.FileBelongsToThisType(filename);

            result.Should().Be(expectedResult);
        }
Beispiel #4
0
        public void TestMultiLocationInfo(string filename, bool expectedResult)
        {
            var singleLocationInfo = new LogTypeInfo(LogType.Apache, _testFunc, new List <Regex>
            {
                new Regex(@"fileOne\.txt", RegexOptions.Compiled),
                new Regex(@"fileTwo\.txt", RegexOptions.Compiled)
            });

            var result = singleLocationInfo.FileBelongsToThisType(filename);

            result.Should().Be(expectedResult);
        }