コード例 #1
0
        public void LogConfigurationSectionConstructorTest()
        {
            LogConfigurationSection target = new LogConfigurationSection();

            Assert.IsNotNull(target);
            Assert.IsInstanceOfType(target, typeof(LogConfigurationSection));
        }
コード例 #2
0
ファイル: LogManager.cs プロジェクト: dzzzq/Giga
 /// <summary>
 /// Load loggers according to configuration
 /// </summary>
 private void LoadLoggers()
 {
     LogConfigurationSection sec = ConfigurationManager.GetSection("Giga.Log") as LogConfigurationSection;
     if (sec == null)
     {   // No logger configured
         System.Diagnostics.Trace.TraceWarning("Giga.Log is not configured!\n");
         return;
     }
     _outputToConsole = sec.OutputToConsole;
     foreach (LoggerConfigurationElement elemLogger in sec.Loggers)
     {
         if (_loggers.ContainsKey(elemLogger.Name))
         {   // Logger already exist
             System.Diagnostics.Trace.TraceWarning(String.Format("Logger {0} already loaded!\n", elemLogger.Name));
         }
         else
         {
             Type loggerType = Type.GetType(elemLogger.Type);
             if (loggerType == null)
             {
                 throw new TypeLoadException(String.Format("Cannot load logger type {0}!", elemLogger.Type));
             }
             Logger logger = loggerType.Assembly.CreateInstance(loggerType.FullName) as Logger;
             if (logger == null)
             {
                 throw new InvalidCastException(String.Format("Cannot cast object of type {0} to Logger!", elemLogger.Type));
             }
             logger.Initialize(elemLogger);
             _loggers.Add(elemLogger.Name, logger);
         }
     }
 }
コード例 #3
0
        public void LoadConfigurationTest()
        {
            AppConfigFactoryResolver_Accessor target        = new AppConfigFactoryResolver_Accessor(); // TODO: Initialize to an appropriate value
            LogConfigurationSection           configuration = null;                                    // TODO: Initialize to an appropriate value

            target.LoadConfiguration(configuration);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
コード例 #4
0
        public void FactoriesTest()
        {
            LogConfigurationSection configSection = ConfigurationManager.GetSection(configurationSection) as LogConfigurationSection;

            Assert.IsNotNull(configSection);
            Assert.AreEqual(1, configSection.Factories.Count);
            Assert.AreEqual(singleFactory.Type, configSection.Factories[0].Type);
            Assert.AreEqual(singleFactory.Name, configSection.Factories[0].Name);
        }
コード例 #5
0
        public void LogsTest()
        {
            LogConfigurationSection configSection = ConfigurationManager.GetSection(configurationSection) as LogConfigurationSection;

            Assert.IsNotNull(configSection);
            Assert.AreEqual(1, configSection.Logs.Count);
            Assert.AreEqual(singleLog.LogName, configSection.Logs[0].LogName);
            Assert.AreEqual(singleLog.FactoryName, configSection.Logs[0].FactoryName);
        }
コード例 #6
0
        public void ParseConfigurationTest()
        {
            AppConfigFactoryResolver_Accessor target   = new AppConfigFactoryResolver_Accessor(); // TODO: Initialize to an appropriate value
            LogConfigurationSection           expected = null;                                    // TODO: Initialize to an appropriate value
            LogConfigurationSection           actual;

            actual = target.ParseConfiguration();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #7
0
        static Log()
        {
            ILogConfiguration configuration = LogConfigurationSection.Get();

            if (configuration == null)
            {
                return;
            }

            SetConfiguration(configuration);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        private void Init()
        {
            logProviders = new Dictionary <string, string>();

            // Call ConfigurationManager to read the custom logConfiguration
            // of the web.config file and put its contents into an
            // instance of the custom class created for it.
            LogConfigurationSection configSection = ConfigurationManager.GetSection("logConfiguration") as LogConfigurationSection;

            if (configSection == null)
            {
                throw new ApplicationException("Failed to load the Log Configuration section.");
            }
            else
            {
                for (int i = 0; i < configSection.LogProviders.Count; i++)
                {
                    logProviders.Add(configSection.LogProviders[i].Name, configSection.LogProviders[i].Type);
                }
            }
        }
コード例 #9
0
        /// <summary> Prepares the internal dictionaries and caches for factory requests, but without already creating the factory instances. </summary>
        /// <param name="configuration"> An configuration section that provides configuration settings about factories and loggers. </param>
        protected void LoadConfiguration(LogConfigurationSection configuration)
        {
            // construct the named factories.
            var factories = new Dictionary <string, ILogFactory>();

            if (configuration != null && configuration.Factories != null)
            {
                foreach (FactoryConfigurationElement factoryConfiguration in configuration.Factories)
                {
                    ILogFactory factory = CreateFactoryInstance(factoryConfiguration);

                    if (factories.ContainsKey(factoryConfiguration.Name))
                    {
                        DiagnosticLog.Warn("There are duplicate factories with the name [{0}]", factoryConfiguration.Name);
                    }
                    else
                    {
                        factories.Add(factoryConfiguration.Name, factory);
                    }
                }
            }

            //if there is no default factory, create an implicit entry that resolves to a NullLogFactory
            if (!factories.ContainsKey(LogManager.DefaultLogName))
            {
                factories.Add(LogManager.DefaultLogName, NullLogFactory.Instance);
            }

            //process log configurations
            List <LogConfigurationElement> logConfigurationList = new List <LogConfigurationElement>();

            if (configuration != null && configuration.Logs != null)
            {
                foreach (LogConfigurationElement logConfiguration in configuration.Logs)
                {
                    logConfigurationList.Add(logConfiguration);

                    //make sure a correct factory name is referenced
                    string factoryName = logConfiguration.FactoryName;
                    if (!factories.ContainsKey(factoryName))
                    {
                        const string message = "Declared log configuration '{0}' refers to undeclared log factory '{1}'";
                        DiagnosticLog.Error(message, logConfiguration.LogName, factoryName);

                        // associate with a null logger factory
                        base.RegisterFactory(logConfiguration.LogName, NullLogFactory.Instance);
                    }
                    else
                    {
                        ILogFactory factory = factories[factoryName];
                        base.RegisterFactory(logConfiguration.LogName, factory);
                    }
                }
            }

            // if there is no default log declaration, create one that links to the default factory
            if (logConfigurationList.Find(el => el.LogName == LogManager.DefaultLogName) == null)
            {
                base.RegisterFactory(LogManager.DefaultLogName, factories[LogManager.DefaultLogName]);
            }
        }
コード例 #10
0
        /// <summary> Loads the resolver configuration from the log.config file or the applications App.config file. </summary>
        public virtual void Load()
        {
            LogConfigurationSection config = ParseConfiguration();

            LoadConfiguration(config);
        }