Beispiel #1
0
        /// <summary>
        /// 按指定的配置元素名称创建应用程序日志对象。
        /// </summary>
        /// <param name="elementName">配置元素名称。</param>
        /// <returns>日志对象。</returns>
        /// <remarks>
        /// 1. 配置元素:USe.Common.AppLogger/appLoggers/appLogger。<br/>
        /// 2. 辅助的IAppLogger对象创建方法,与Singleton模式的静态实例变量无关。
        /// </remarks>
        public static IAppLogger CreateInstance(string elementName)
        {
            /*
             * AppLoggerElement element = AppLoggerSectionGroup.FindAppLoggerElement(elementName);
             *          if (element == null)
             *          {
             *                  throw new ArgumentException("Not found the special appLogger configuration element.");
             *          }
             */

            AppLoggersSection section = AppLoggersSection.GetSection();

            if (section == null)
            {
                throw new ConfigurationErrorsException("Not found the appLogger configuration section.");
            }

            return(CreateInstance(section.AppLoggers[elementName]));
        }
Beispiel #2
0
        /// <summary>
        /// 初始化IAppLogger应用程序日志对象。
        /// </summary>
        /// <returns>日志对象。</returns>
        /// <remarks>
        /// Singleton模式的静态实例变量的创建方法。
        /// </remarks>
        public static IAppLogger InitInstance()
        {
            // 检查是否重复初始化
            if (ms_singleInstance != null)
            {
                Debug.Assert(false);
                throw new ApplicationException("IAppLogger object already initialized.");
            }

            AppLoggersSection section = AppLoggersSection.GetSection();

            if (section == null)
            {
                throw new ConfigurationErrorsException("Not found the appLogger configuration section.");
            }

            ms_singleInstance = CreateInstance(section.AppLoggers["Default"]);
            //ms_singleInstance = CreateInstance("Default");
            // 缺省使用名称为"Default"的配置元素,区分大小写

            return(ms_singleInstance);
        }