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); } }
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; } }
public static LogWatcher CreateFromFile(string configFilePath) { try { SettingsReader settingsReader = new SettingsReader(configFilePath); Regex fileMask = new Regex(settingsReader.GetConfigParam("FileMask"), RegexOptions.Compiled); Encoding encoding = Encoding.GetEncoding(settingsReader.GetConfigParam("Encoding")); IEnumerable <string> possibleLogDirectories = settingsReader.GetConfigParams("LogDirectory").SelectMany( FilePathHelpers.FindDirectoriesOnFixedDisks); List <string> directories = possibleLogDirectories.SelectMany(FilePathHelpers.GetDirectoriesByMaskedPath).Distinct().ToList(); return(new LogWatcher(configFilePath, directories, fileMask, encoding)); } catch (Exception ex) { _logger.Error("Cannot load LogWatcher from " + configFilePath + ": " + ex); return(null); } }
public static LogWatcher CreateFromFile(string configFilePath) { try { SettingsReader settingsReader = new SettingsReader(configFilePath); Regex fileMask = new Regex(settingsReader.GetConfigParam("FileMask"), RegexOptions.Compiled); Encoding encoding = Encoding.GetEncoding(settingsReader.GetConfigParam("Encoding")); IEnumerable<string> possibleLogDirectories = settingsReader.GetConfigParams("LogDirectory").SelectMany( FilePathHelpers.FindDirectoriesOnFixedDisks); List<string> directories = possibleLogDirectories.SelectMany(FilePathHelpers.GetDirectoriesByMaskedPath).Distinct().ToList(); return new LogWatcher(configFilePath, directories, fileMask, encoding); } catch (Exception ex) { _logger.Error("Cannot load LogWatcher from " + configFilePath + ": " + ex); return null; } }