public async Task ProcessValidStdErrStream(string value)
        {
            var storage = new KongoDataStorage($"Data Source={Path.GetRandomFileName()}");

            storage.Database.EnsureCreated();
            _processor = new StdErrorProcessor(storage);
            await _processor.IngestLogEntry(value, 1);

            var logs = await _processor.ProcessIngestedLogs();

            storage.Database.EnsureDeleted();
        }
예제 #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var linesRead = 0;

            using Stream stream = File.Open(_logIngestionConfig.Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using (StreamReader reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    var logLine = reader.ReadLine();
                    await _processor.IngestLogEntry(logLine, linesRead ++);

                    _logger.LogDebug(logLine);
                }

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                // Get the elapsed time as a TimeSpan value.
                TimeSpan ts = stopWatch.Elapsed;

                while (stoppingToken.IsCancellationRequested)
                {
                    if (!reader.EndOfStream)
                    {
                        var logLine = reader.ReadLine();
                        await _processor.IngestLogEntry(logLine, linesRead ++);

                        _logger.LogDebug(logLine);
                    }
                    else
                    {
                        if (_stopwatch.Elapsed > TimeSpan.FromSeconds(30))
                        {
                            var processedLogModel = await _processor.ProcessIngestedLogs();

                            _sb.Clear();
                            _sb.AppendLine($"Log Summary on {_opts.PoolName}, at: {DateTimeOffset.Now}");
                            _sb.AppendLine();

                            _logger.LogInformation(_sb.ToString());
                            _stopwatch.Restart();
                        }
                        else
                        {
                            await Task.Delay(1000, stoppingToken);
                        }
                    }
                }
                _stopwatch.Stop();
            }
        }