public LogWatcher(string configFilePath, List <string> watchedDirectories, Regex fileMask, Encoding encoding)
            : base(Path.ChangeExtension(configFilePath, "rules"), "*")
        {
            _logger.Info("Watcher for " + configFilePath + " monitors files in folders:\r\n" + String.Join("\r\n", watchedDirectories.ToArray()));
            _logWatcherConfigFilePath = configFilePath;
            _logEventEvaluatorRulesConfigDirectoryPath = Path.ChangeExtension(_logWatcherConfigFilePath, "rules");
            if (!Directory.Exists(_logEventEvaluatorRulesConfigDirectoryPath))
            {
                throw new Exception("Directory with rules does not exists");
            }

            WatchedDirectories = watchedDirectories;
            FileMask           = fileMask;
            Encoding           = encoding;
            ReloadRules();
            foreach (string logDirectory in WatchedDirectories)
            {
                List <string> currentLogs = new DirectoryInfo(logDirectory).GetFiles().Where(fi => fi.LastWriteTime >= DateTime.Now.Date).Select(fi => fi.FullName).ToList();
                foreach (var currentLog in currentLogs)
                {
                    AddReaderWithFileNameCheck(currentLog);
                }
            }
            _multiDirectoryFileChangeMonitor = new MultiDirectoryFileChangeMonitor(watchedDirectories, AddReaderWithFileNameCheck, RemoveReaderWithFileNameCheck, null, null);
        }
        public LogWatcher(string configFilePath, List<string> watchedDirectories, Regex fileMask, Encoding encoding)
            : base(Path.ChangeExtension(configFilePath, "rules"), "*")
        {
            _logger.Info("Watcher for "+configFilePath+" monitors files in folders:\r\n" + String.Join("\r\n",watchedDirectories.ToArray()));
            _logWatcherConfigFilePath = configFilePath;
            _logEventEvaluatorRulesConfigDirectoryPath = Path.ChangeExtension(_logWatcherConfigFilePath, "rules");
            if (!Directory.Exists(_logEventEvaluatorRulesConfigDirectoryPath)) 
                throw new Exception("Directory with rules does not exists");

            WatchedDirectories = watchedDirectories;
            FileMask = fileMask;
            Encoding = encoding;
            ReloadRules();
            foreach (string logDirectory in WatchedDirectories)
            {
                List<string> currentLogs = new DirectoryInfo(logDirectory).GetFiles().Where(fi => fi.LastWriteTime >= DateTime.Now.Date).Select(fi => fi.FullName).ToList();
                foreach (var currentLog in currentLogs)
                {
                    AddReaderWithFileNameCheck(currentLog);
                }
            }
            _multiDirectoryFileChangeMonitor = new MultiDirectoryFileChangeMonitor(watchedDirectories, AddReaderWithFileNameCheck, RemoveReaderWithFileNameCheck, null, null);
        }
        private static void Main(string[] args)
        {
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.UseNagleAlgorithm = false;
            ServicePointManager.DefaultConnectionLimit = 10;
            _reconnectTimer = new Timer(CreateTcpClientTimerWrapper);
            _logger.Info("Starting App...");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            if (args.Length > 0 && args[0].ToLower() == "debug")
                _debug = true;

            MultiDirectoryFileChangeMonitor serverConfig = null;
            if (!_debug)
            {
                CreateTcpClient("settings\\ServerAddress");
                serverConfig = new MultiDirectoryFileChangeMonitor(Path.GetFullPath("settings\\"), CreateTcpClient, null, ServerConfigChanged, null);
                
            }

            LogWatcherManager logWatcherManager = new LogWatcherManager(".\\settings\\LogDescriptions\\");


            if (_debug)
                logWatcherManager.EventFromLog +=
                    (s, ev) => OutToConsole(null, ev.LogEvent);
            else
            {
                logWatcherManager.EventFromLog +=
                    (s, ev) => CountEvents(null, ev.LogEvent);
                logWatcherManager.EventFromLog +=
                    (s, ev) => OutToHttpServer(null, ev.LogEvent);
            }

            Console.ReadKey();
            if (serverConfig != null) 
                serverConfig.Dispose();
        }