public static string GetConfigXML(Settings input, bool includeRoot = false)
        {
            StringBuilder sb = new StringBuilder();

            if (includeRoot)
                sb.Append($"<{input.Name}>");

            foreach(var key in input.Keys)
                sb.Append(writeNodeRecursive(key, input[key]));

            if (includeRoot)
                sb.Append($"</{input.Name}>");

            return sb.ToString();
        }
        public void Init(Settings settings)
        {
            //Setup Settings
            string xmlString = string.Empty;
            try
            {
                xmlString = settings.ToXML();
                var configDoc = new XmlDocument();
                configDoc.LoadXml(xmlString);
                log4net.Config.XmlConfigurator.Configure(configDoc.DocumentElement);
            }
            catch (Exception e)
            {
                throw new ConfigurationException($"Log4NetProvider - Unable to load configuration data. Configuration: {xmlString ?? string.Empty} ", e);
            }

            //Inject into Logger
            Logger.Load(this);
        }
Beispiel #3
0
        private static void autoInitProviders(Settings settings)
        {
            foreach(var pair in settings)
            {
                if (pair.Value is JObject)
                {
                    autoInitProviders(((JObject)pair.Value).ToObject<Settings>());
                    continue;
                }

                if(pair.Key.Equals("Provider"))
                {
                    var enabled = settings["Enabled"] != null && ((bool)settings["Enabled"] == true);
                    if(enabled)
                    {
                        IProvider provider = null;
                        try
                        {
                            provider = (IProvider)Activator.CreateInstance(Type.GetType((string)pair.Value, true, true));
                        }
                        catch(Exception e)
                        {
                            throw new ConfigurationException($"Unable to locate 'Provider' type specified: {pair.Value}", e);
                        }

                        if(provider==null)
                            throw new ConfigurationException($"Unable to activate 'Provider' type specified: {pair.Value}");

                        var providerSettings = settings[provider.ConfigSectionName] as Settings ?? new Settings();
                        provider.Enabled = enabled;
                        provider.Init(providerSettings);
                    }
                }
            }
        }