public void InitialRead(string directory, ICentralLogServiceCache cache, int maxLinesToRead = 1000)
        {
            if (_readDone)
            {
                return;
            }

            _current.ContinueWith((task) =>
            {
                var token = _tokenSource.Token;
                if (token.IsCancellationRequested)
                {
                    return;
                }

                var files = Directory.GetFiles(directory);

                // ReSharper disable once LocalizableElement
                Console.WriteLine($"Read simulation files from [{directory}]");
                Parallel.ForEach(files, (file) =>
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    var lines = File.ReadAllLines(file);
                    if (maxLinesToRead != -1)
                    {
                        foreach (var line in lines.Take(maxLinesToRead))
                        {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            cache.AddEntry(new LogEntry(file, line));
                        }
                    }
                    else
                    {
                        foreach (var line in lines)
                        {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            cache.AddEntry(new LogEntry(file, line));
                        }
                    }
                });

                _readDone = true;
            });
        }
Esempio n. 2
0
        // ReSharper disable once UnusedMember.Global
        public void ConfigureOwnServices(ICentralLogServiceWatcher centralWatcher, LogSimulatorReadAllContent logSimulator, ICentralLogServiceCache cache)
        {
            centralWatcher.Start();

            bool logSimulatorActive = Configuration.GetValue <bool>("EnableLogSimulatorReadFromEachFile");

            if (logSimulatorActive)
            {
                string directory = Configuration["LogSimulatorDirectory"];
                int    maxLines  = Configuration.GetValue <int>("MaxLogSimulatorLinesToReadFromEachFile");
                logSimulator.InitialRead(directory, cache, maxLines);
            }
        }
 /// <summary>
 /// Creates a central object used to aggregate all incomming log entries
 /// </summary>
 /// <param name="maxEntriesInChannelQueue">Specifies how man entries can be added asynchronously to the channgel</param>
 public CentralLogService(ILogger <CentralLogServiceCache> logger, IConfiguration config, ICentralLogServiceCache cache = null, int maxEntriesInChannelQueue = 1024)
 {
     _logEntryChannel = Channel.CreateBounded <LogEntry>(maxEntriesInChannelQueue);
     _cache           = cache; // ?? new CentralLogServiceCache(new CentralLogServiceCacheSettings { }, config, logger);
 }
 public SearchCommandHandler(ICentralLogServiceCache cache, ILogger <SearchCommandHandler> logger)
 {
     _logger     = logger;
     _cacheQuery = cache;
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a central object used to aggregate all incomming log entries
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="maxEntriesInChannelQueue">Specifies how man entries can be added asynchronously to the channgel</param>
 public CentralLogService(ICentralLogServiceCache cache = null, int maxEntriesInChannelQueue = 1024)
 {
     _logEntryChannel = Channel.CreateBounded <LogEntry>(maxEntriesInChannelQueue);
     _cache           = cache ?? throw new ArgumentNullException(nameof(cache)); // ?? new CentralLogServiceCache(new CentralLogServiceCacheSettings { }, config, logger);
 }