예제 #1
0
        public static void ClientVersion3()
        {
            LoggerFactory factory = (LoggerFactory)AppConfigHelper.GetLoggerFactoryInstance();

            if (factory == null)
            {
                return;
            }

            factory.WriteLog();
        }
예제 #2
0
        public static void ClientVersion2()
        {
            ILoggerFactory factory = (ILoggerFactory)AppConfigHelper.GetLoggerFactoryInstance();

            if (factory == null)
            {
                return;
            }

            ILogger logger = factory.CreateLogger();

            logger.WriteLog();
        }
예제 #3
0
        /*
         * 工厂方法(Factory Method)模式:定义一个用于创建对象的接口,让子类决定将哪一个类实例化。工厂方法模式让一个类的实例化延迟到其子类。工厂方法模式又简称为工厂模式,也可称为多态工厂模式,它是一种创建型模式。  
         */
        static void Main(string[] args)
        {
            #region  隐藏工厂方法
            var factory = new DAL.FileLoggerFactory(); // 可通过引入配置文件实现
            if (factory == null)
            {
                return;
            }

            var logger = factory.CreateLogger();
            logger.WriteLog();
            #endregion

            #region 隐藏工厂方法
            var factory1 = (LoggerFactory)AppConfigHelper.GetLoggerFactoryInstance();
            if (factory1 == null)
            {
                return;
            }

            factory1.WriteLog();
            #endregion
            Console.ReadKey();
        }