Ejemplo n.º 1
0
        public static void PushLocalLogToDb()
        {
            lock (locker)
            {
                if (checkForLog == true)
                {
                    if (File.Exists(logFile))
                    {
                        List<CrawlerLog> crawlerLogs = new List<CrawlerLog>();
                        StreamReader sr = new StreamReader(logFile);
                        using (sr)
                        {
                            string line;
                            while ((line = sr.ReadLine()) != null)
                            {
                                crawlerLogs.Add(GetLog(line));

                                if (crawlerLogs.Count > 300)
                                {
                                    db.AddNewLogRange(crawlerLogs);
                                    crawlerLogs.Clear();
                                }
                            }
                        }

                        if (crawlerLogs.Count > 0)
                        {
                            db.AddNewLogRange(crawlerLogs);
                        }

                        File.Delete(logFile);
                    }

                    checkForLog = false;
                }
            }
        }