Пример #1
0
        static void Main(string[] args)
        {
            int appendersCount = int.Parse(Console.ReadLine());
            ICollection <IAppender> appenders = new List <IAppender>();

            ParseAppendersInput(appendersCount, appenders);

            ILogger logger = new Logger.Models.Logger(appenders);
            IEngine engine = new Engine(logger);

            engine.Run();
        }
Пример #2
0
        static void Main(string[] args)
        {
            int appendersCount = int.Parse(Console.ReadLine());
            ICollection <IAppender> appenders       = new List <IAppender>();
            AppenderFactory         appenderFactory = new AppenderFactory();

            ReadAppendersData(appendersCount, appenders, appenderFactory);

            ILogger logger = new Logger.Models.Logger(appenders);
            Engine  engine = new Engine(logger);

            engine.Run();
        }
        static void Main(string[] args)
        {
            int appenderscount = int.Parse(Console.ReadLine());

            ICollection <IAppender> appenders = new List <IAppender>();

            AppendersFactory factory = new AppendersFactory();

            for (int i = 0; i < appenderscount; i++)
            {
                var cmdargs = Console.ReadLine().Split(" ").ToArray();
                if (cmdargs.Length == 2)
                {
                    try
                    {
                        var       appendertype = cmdargs[0];
                        var       layouttype   = cmdargs[1];
                        var       level        = "INFO";
                        IAppender appender     = factory.ProduceAppender(appendertype, layouttype, level);
                        appenders.Add(appender)
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (cmdargs.Length == 3)
                {
                    try
                    {
                        var       appendertype = cmdargs[0];
                        var       layouttype   = cmdargs[1];
                        var       reportlevel  = cmdargs[2];
                        IAppender appender     = factory.ProduceAppender(appendertype, layouttype, reportlevel);
                        appenders.Add(appender);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            ILogger logger = new Logger.Models.Logger(appenders);
            Engine  engine = new Engine(logger);

            engine.Run();
        }
Пример #4
0
        private static ILogger CreateLogger(int appendersCount, IReader reader, IWriter writer, IFile file, LayoutFactory layoutFactory, AppenderFactory appenderFactory)
        {
            ICollection <IAppender> appenders = new List <IAppender>();

            for (int i = 0; i < appendersCount; i++)
            {
                string[] appenderInfo     = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   appenderType     = appenderInfo[0];
                string   layoutType       = appenderInfo[1];
                Level    appenderTreshold = Level.INFO;
                if (appenderInfo.Length == 3)
                {
                    bool isValidLevel = Enum.TryParse(typeof(Level), appenderInfo[2], true, out object enumParsed);
                    if (!isValidLevel)
                    {
                        writer.WriteLine(GlobalConstants.INVALID_INPUT);
                    }
                    else
                    {
                        appenderTreshold = (Level)enumParsed;
                    }
                }
                try
                {
                    ILayout   layout   = layoutFactory.CreateLayout(layoutType);
                    IAppender appender = appenderFactory.CreateAppender(appenderType, layout, appenderTreshold, file);
                    appenders.Add(appender);
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            ILogger logger = new Logger.Models.Logger(appenders);

            return(logger);
        }