/// <summary> /// Instances this instance. /// </summary> /// <returns> /// </returns> /// <remarks> /// </remarks> public static LogProvider Instance() { // Use the cache because the reflection used later is expensive var cache = HttpRuntime.Cache; // Get the names of providers var config = ProviderConfiguration.GetProviderConfiguration(ProviderType); // If config not found (missing web.config) if (config == null) { // Try to provide a default anyway var defaultNode = new XmlDocument(); defaultNode.LoadXml( "<log defaultProvider=\"Log4NetLog\"><providers><clear /><add name=\"Log4NetLog\" type=\"Appleseed.Framework.Logging.Log4NetLogProvider, Appleseed.Provider.Implementation\" /></providers></log>"); // Get the names of providers config = new ProviderConfiguration(); config.LoadValuesFromConfigurationXml(defaultNode.DocumentElement); } // Read specific configuration information for this provider var providerSettings = (ProviderSettings)config.Providers[config.DefaultProvider]; // In the cache? var cacheKey = "Appleseed::Configuration::Log::" + config.DefaultProvider; if (cache[cacheKey] == null) { // The assembly should be in \bin or GAC, so we simply need // to get an instance of the type try { cache.Insert(cacheKey, ProviderHelper.InstantiateProvider(providerSettings, typeof(LogProvider))); } catch (Exception e) { throw new Exception("Unable to load provider", e); } } return (LogProvider)cache[cacheKey]; }
/// <summary> /// Creates the specified parent. /// </summary> /// <param name="parent"> /// The parent. /// </param> /// <param name="context"> /// The context. /// </param> /// <param name="node"> /// The configuration node. /// </param> /// <returns> /// The create. /// </returns> /// <remarks> /// </remarks> public virtual object Create(object parent, object context, XmlNode node) { var config = new ProviderConfiguration(); config.LoadValuesFromConfigurationXml(node); return config; }