internal static void CoreFetch() { string nutFile = "_cocohub.log.nut"; if (File.Exists(nutFile)) { //try to restore the last read postion string[] lines = File.ReadAllLines(nutFile); if (lines.Length == 2) { var lastFile = lines[0].Trim(); var lastPos = lines[1].Trim(); if (File.Exists(lastFile) && long.TryParse(lastPos, out long result)) { LogReader.LastFile = lastFile; LogReader.LastPosition = result; } } } while (_running) { try { if (_logs.Count > 1000) { Thread.Sleep(1000); continue; } var logs = LogReader.Fetch(); if (logs == null || logs.Length == 0) { Thread.Sleep(1000); continue; } Parallel.ForEach(logs, (log) => { _logs.Enqueue(log); }); Thread.Sleep(1000); } catch (Exception ex) { Console.WriteLine("Log agent error:CoreFetch. " + ex.Message); Console.WriteLine(ex.StackTrace); Thread.Sleep(10000); } } File.WriteAllLines(nutFile, new string[] { LogReader.LastFile, LogReader.LastPosition.ToString() }); }