private static void ParseAppendersInput(int appendersCount, ICollection <IAppender> appenders) { AppendersFactory appendersFactory = new AppendersFactory(); for (int i = 0; i < appendersCount; i++) { string[] appendersArgs = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries) .ToArray(); string appenderType = appendersArgs[0]; string layoutType = appendersArgs[1]; string reportLevel = "INFO"; if (appendersArgs.Length == 3) { reportLevel = appendersArgs[2]; } try { IAppender appender = appendersFactory .ProduceAppender(appenderType, layoutType, reportLevel); appenders.Add(appender); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } }
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(); }