public static EventEvaluatorRule CreateFromFile(string configFilePath)
        {
            try
            {
                SettingsReader settingsReader = new SettingsReader(configFilePath);
                EventType eventType = GetEventType(settingsReader.GetConfigParam("Type"));
                string eventSource = settingsReader.GetConfigParam("Source");
                string counterCategory = settingsReader.GetConfigParam("Category");
                string counterName = settingsReader.GetConfigParam("Counter");
                string counterInstance = settingsReader.GetConfigParam("Instance", false);
                string extendedData = settingsReader.GetConfigParam("ExtendedData", false);
                string value = settingsReader.GetConfigParam("Value");
                string dateTime = settingsReader.GetConfigParam("DateTime");
                string dateFormat = settingsReader.GetConfigParam("DateFormat");
                Regex regexRule = new Regex(settingsReader.GetConfigParam("Regex"), RegexOptions.Compiled);
                List<Regex> excludingRules =
                    settingsReader.GetConfigParams("ExcludeRegex",false).Distinct().Select(r => new Regex(r, RegexOptions.Compiled)).
                        ToList();

                var eventEvaluatorRule = new EventEvaluatorRule(eventType, regexRule, excludingRules, eventSource, counterCategory,
                                  counterInstance, counterName, extendedData, value,
                                  dateTime, dateFormat);
                _logger.Debug("Rule created from {0} is {2} and has {1} excludings",configFilePath, eventEvaluatorRule.ExcludingRules.Count, eventEvaluatorRule.RegexRule.ToString());
                return eventEvaluatorRule;
            }
            catch (Exception ex)
            {
                _logger.Error("Cannot load EventEvaluatorRule from " + configFilePath + ": " + ex);
                return null;
            }

        }
Beispiel #2
0
        public static EventEvaluatorRule CreateFromFile(string configFilePath)
        {
            try
            {
                SettingsReader settingsReader  = new SettingsReader(configFilePath);
                EventType      eventType       = GetEventType(settingsReader.GetConfigParam("Type"));
                string         eventSource     = settingsReader.GetConfigParam("Source");
                string         counterCategory = settingsReader.GetConfigParam("Category");
                string         counterName     = settingsReader.GetConfigParam("Counter");
                string         counterInstance = settingsReader.GetConfigParam("Instance", false);
                string         extendedData    = settingsReader.GetConfigParam("ExtendedData", false);
                string         value           = settingsReader.GetConfigParam("Value");
                string         dateTime        = settingsReader.GetConfigParam("DateTime");
                string         dateFormat      = settingsReader.GetConfigParam("DateFormat");
                Regex          regexRule       = new Regex(settingsReader.GetConfigParam("Regex"), RegexOptions.Compiled);
                List <Regex>   excludingRules  =
                    settingsReader.GetConfigParams("ExcludeRegex", false).Distinct().Select(r => new Regex(r, RegexOptions.Compiled)).
                    ToList();

                var eventEvaluatorRule = new EventEvaluatorRule(eventType, regexRule, excludingRules, eventSource, counterCategory,
                                                                counterInstance, counterName, extendedData, value,
                                                                dateTime, dateFormat);
                _logger.Debug("Rule created from {0} is {2} and has {1} excludings", configFilePath, eventEvaluatorRule.ExcludingRules.Count, eventEvaluatorRule.RegexRule.ToString());
                return(eventEvaluatorRule);
            }
            catch (Exception ex)
            {
                _logger.Error("Cannot load EventEvaluatorRule from " + configFilePath + ": " + ex);
                return(null);
            }
        }
        private void ReloadRules()
        {
            List <EventEvaluatorRule> rules = new List <EventEvaluatorRule>();

            FileInfo[] fileInfos = new DirectoryInfo(_logEventEvaluatorRulesConfigDirectoryPath).GetFiles();
            foreach (FileInfo fileInfo in fileInfos)
            {
                EventEvaluatorRule rule = EventEvaluatorRule.CreateFromFile(fileInfo.FullName);
                if (rule != null)
                {
                    rules.Add(rule);
                }
            }
            _eventEvaluator.Configure(rules);
            _logger.Debug("Rules for " + _logWatcherConfigFilePath + " were reloaded");
        }