/// <summary> /// <para> /// Adds a new flat configuration node with given name attribute and values /// </para> /// </summary> /// /// <param name="parent"> /// The parent configuration of the new node. /// </param> /// <param name="name"> /// The name of the new configuration. /// </param> /// <param name="values"> /// The values of the new configuration. /// </param> /// <param name="propertyIndex"> /// The index of the new node. /// </param> /// /// <returns> /// The configuration created. /// </returns> private static void AddNewFlatConfig(IConfiguration parent, int propertyIndex, string name, params object[] values) { if (values[0] == null) { return; } // The property node IConfiguration child = new DefaultConfiguration(ConfigProperty + "_" + propertyIndex); child.SetSimpleAttribute(ConfigName, name); // The value nodes int index = 0; foreach (object value in values) { if (value != null) { IConfiguration valueNode = new DefaultConfiguration(ConfigValue + "_" + (++index)); valueNode.SetSimpleAttribute(ConfigNodeValue, value.ToString()); child.AddChild(AbstractConfiguration.Synchronized(valueNode)); } } // Add the new property node parent.AddChild(AbstractConfiguration.Synchronized(child)); }
/// <summary> /// <para> /// Adds a new nested configuration node with given name and values /// </para> /// </summary> /// /// <param name="parent"> /// The parent configuration of the new node. /// </param> /// <param name="name"> /// The name of the new configuration. /// </param> /// <param name="values"> /// The values of the new configuration. /// </param> /// /// <returns> /// The configuration created. /// </returns> private static IConfiguration AddNewNestedConfig(IConfiguration parent, string name, params object[] values) { if (values[0] == null) { return null; } IConfiguration child = new DefaultConfiguration(name); child.SetAttribute(ConfigValue, ToStringArray(values)); parent.AddChild(AbstractConfiguration.Synchronized(child)); return child; }
/// <summary> /// <para> /// Saves the given parameters in NESTED hierarchical structure. /// </para> /// </summary> /// /// <param name="types"> /// The parameter types. /// </param> /// <param name="values"> /// The parameter values. /// </param> /// <param name="parent"> /// The object configuration. /// </param> private void SaveNestedParameters(IConfiguration parent, string[] types, object[] values) { IConfiguration paramsConfig = new DefaultConfiguration(ConfigParameters); for (int i = 0; i < types.Length; ++i) { string childName = ConfigParameter + "_" + (i + 1); IConfiguration paramConfig; if (types[i] == NullType) { // null parameter paramConfig = AddNewNestedConfig(paramsConfig, childName, String.Empty); } else { Array array = values[i] as Array; if (array == null) { // Simple parameter paramConfig = AddNewNestedConfig(paramsConfig, childName, values[i]); } else { // Array parameter paramConfig = AddNewNestedConfig(paramsConfig, childName, ToStringArray(array)); } } // Add the type of the parameter paramConfig.SetSimpleAttribute(ConfigType, types[i]); } parent.AddChild(AbstractConfiguration.Synchronized(paramsConfig)); }
/// <summary> /// <para> /// Saves the given method definition in NESTED hierarchical structure. /// </para> /// </summary> /// /// <param name="name"> /// The method unique name. /// </param> /// <param name="definition"> /// The method definition to be saved. /// </param> /// <param name="parent"> /// The methods configuration. /// </param> private void SaveNestedMethodDefinition(IConfiguration parent, string name, MethodCallDefinition definition) { // The config of the definition IConfiguration methodConfig = new DefaultConfiguration(name); // Write all simple attributes of the definition AddNewNestedConfig(methodConfig, ConfigIgnoreCase, definition.IgnoreCase); AddNewNestedConfig(methodConfig, ConfigMethodName, definition.MethodName); AddNewNestedConfig(methodConfig, ConfigIsProperty, definition.IsProperty); if (definition.ParamTypes.Length > 0) { // Write the parameter definitions of the method SaveNestedParameters(methodConfig, definition.ParamTypes, definition.ParamValues); } // Add the new method configuration into methods config parent.AddChild(AbstractConfiguration.Synchronized(methodConfig)); }
protected void SetUp() { namedMsg = new NamedMessage(MESSAGE, NAMEDMESSAGE, new List<string>(PARAMETER_NAMES), Level.ERROR); config = new DefaultConfiguration("default"); config.SetSimpleAttribute("logger_name", LOGGER_NAME); config.SetSimpleAttribute("default_level", DEFAULT_LEVEL.ToString()); IConfiguration msgsConfig = new DefaultConfiguration("NamedMessages"); IConfiguration msgConfig = new DefaultConfiguration(NAMEDMESSAGE); msgConfig.SetSimpleAttribute("text", MESSAGE); msgConfig.SetSimpleAttribute("default_level", Level.DEBUG.ToString()); msgConfig.SetAttribute("parameters", new object[] {PARAMETER_NAMES[0], PARAMETER_NAMES[1]}); msgsConfig.AddChild(msgConfig); config.AddChild(msgsConfig); simpleLogger = new SimpleLogger(config); anotherLogger = new AnotherSimpleLogger(EXCEPTION_LOGGER_NAME); logger = new ExceptionSafeLogger(simpleLogger, anotherLogger); }
protected void SetUp() { namedMsg = new NamedMessage(MESSAGE, NAMEDMESSAGE, new List<string>(PARAMETER_NAMES), Level.ERROR); config = new DefaultConfiguration("default"); config.SetSimpleAttribute("logger_name", LOGNAME); config.SetSimpleAttribute("default_level", DEFAULT_LEVEL.ToString()); config.SetSimpleAttribute("config_file", CONFIG_FILE); IConfiguration msgsConfig = new DefaultConfiguration("NamedMessages"); IConfiguration msgConfig = new DefaultConfiguration(NAMEDMESSAGE); msgConfig.SetSimpleAttribute("text", MESSAGE); msgConfig.SetSimpleAttribute("default_level", Level.DEBUG); msgConfig.SetAttribute("parameters", new object[] {PARAMETER_NAMES[0], PARAMETER_NAMES[1]}); msgsConfig.AddChild(msgConfig); config.AddChild(msgsConfig); logger = new Log4NETImpl(config); }
protected void SetUp() { IList<string> param = new List<string>(); param.Add("param1"); param.Add("param2"); namedMsg = new NamedMessage("text1", NAME1, param, Level.ERROR); msgs = new Dictionary<string, NamedMessage>(); msgs.Add(NAME1, namedMsg); msgs.Add(NAME2, new NamedMessage("text2", NAME2, new List<string>(), Level.WARN)); config = new DefaultConfiguration("default"); config.SetSimpleAttribute("logger_name", LOGNAME); config.SetSimpleAttribute("default_level", LEVEL.ToString()); IConfiguration msgsConfig = new DefaultConfiguration("NamedMessages"); IConfiguration msgConfig = new DefaultConfiguration(NAME1); msgConfig.SetSimpleAttribute("text", "text1"); msgConfig.SetSimpleAttribute("default_level", Level.ERROR); msgConfig.SetAttribute("parameters", new object[] {"param1", "param2"}); msgsConfig.AddChild(msgConfig); msgConfig = new DefaultConfiguration(NAME2); msgConfig.SetSimpleAttribute("text", "text2"); msgConfig.SetSimpleAttribute("default_level", Level.WARN); msgsConfig.AddChild(msgConfig); config.AddChild(msgsConfig); logger = new SimpleLogger(LOGNAME, LEVEL, msgs); }