Пример #1
0
        private static ILogger InitializeLogger()
        {
            var appenders       = new List <IAppender>();
            var layoutFactory   = new LayoutFactory();
            var appenderFactory = new AppenderFactory(layoutFactory);

            var appenderCount = int.Parse(Console.ReadLine());

            for (var i = 0; i < appenderCount; i++)
            {
                var cmdArgs = Console.ReadLine()
                              .Split()
                              .ToArray();

                var appenderType = cmdArgs[0];
                var layoutType   = cmdArgs[1];
                var errorLevel   = "Info";

                if (cmdArgs.Length == 3)
                {
                    errorLevel = cmdArgs[2];
                }

                var appender = appenderFactory.CreateAppender(appenderType, errorLevel, layoutType);
                appenders.Add(appender);
            }

            var logger = new Logger(appenders);

            return(logger);
        }
Пример #2
0
        private static void ParseAppendersInput(int appendersCount, AppenderFactory appenderFactory, ICollection <IAppender> appenders)
        {
            for (int counter = 0; counter < appendersCount; counter++)
            {
                var appendersArgs = Console.ReadLine()
                                    .Split(' ');

                var type   = appendersArgs[0];
                var layout = appendersArgs[1];
                var level  = "INFO";

                if (appendersArgs.Length == 3)
                {
                    level = appendersArgs[2];
                }

                IAppender currentAppender;

                try
                {
                    currentAppender = appenderFactory.GetAppender(type, layout, level);
                    appenders.Add(currentAppender);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
        }
Пример #3
0
        private static ILogger InitializeLogger()
        {
            var appenders       = new List <IAppender>();
            var appendersCount  = int.Parse(Console.ReadLine());
            var layoutFactory   = new LayoutFactory();
            var appenderFactory = new AppenderFactory(layoutFactory);

            for (int i = 0; i < appendersCount; i++)
            {
                var inputTokens = Console.ReadLine()
                                  .Split(' ', StringSplitOptions.RemoveEmptyEntries);

                var appenderType = inputTokens[0];
                var layoutType   = inputTokens[1];
                var errorLevel   = ErrorLevel.INFO;

                if (inputTokens.Length == 3)
                {
                    errorLevel = (ErrorLevel)Enum.Parse(typeof(ErrorLevel), inputTokens[2]);
                }

                var appender = appenderFactory.GetAppender(appenderType, errorLevel, layoutType);
                appenders.Add(appender);
            }

            var logger = new Logger(appenders);

            return(logger);
        }
Пример #4
0
        private static void ParseAppendersInput(int count, ICollection <IAppender> appenders)
        {
            for (int i = 0; i < count; i++)
            {
                AppenderFactory appenderFactory = new AppenderFactory();
                var             appenderArg     = Console.ReadLine().Split('|', StringSplitOptions.RemoveEmptyEntries).ToArray();
                var             appenderType    = appenderArg[0];
                var             layoutType      = appenderArg[1];
                var             level           = "INFO";

                if (appenderArg.Length == 3)
                {
                    level = appenderArg[2];
                }

                try
                {
                    var appender = appenderFactory.ProduceAppender(appenderType, layoutType, level);
                    appenders.Add(appender);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        static ILogger InitializeLogger()
        {
            ICollection <IAppender> appenders       = new List <IAppender>();
            LayoutFactory           layoutFactory   = new LayoutFactory();
            AppenderFactory         appenderFactory = new AppenderFactory(layoutFactory);

            int appenderCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < appenderCount; i++)
            {
                string[] inputArgs    = Console.ReadLine().Split();
                string   appenderType = inputArgs[0];
                string   layoutType   = inputArgs[1];
                string   errorLevel   = "INFO";

                if (inputArgs.Length == 3)
                {
                    errorLevel = inputArgs[2];
                }

                IAppender appender = appenderFactory.CreateAppender(appenderType, errorLevel, layoutType);
                appenders.Add(appender);
            }

            ILogger logger = new Logger(appenders);

            return(logger);
        }
        private static void ReadAppendersData(int appendersCount,
                                              ICollection <IAppender> appenders, AppenderFactory appenderFactory)
        {
            for (int i = 0; i < appendersCount; i++)
            {
                string[] appendersInfo = Console.ReadLine()
                                         .Split()
                                         .ToArray();

                string appenderType = appendersInfo[0];
                string layoutType   = appendersInfo[1];
                string levelString  = "INFO";

                if (appendersInfo.Length == 3)
                {
                    levelString = appendersInfo[2];
                }


                try
                {
                    IAppender appender = appenderFactory.GetAppender(appenderType,
                                                                     layoutType, levelString);

                    appenders.Add(appender);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
            }
        }
        static ILogger InitializeILogger()
        {
            int appenderCount = int.Parse(Console.ReadLine());

            var appenders       = new IAppender[appenderCount];
            var layoutFactory   = new LayoutFactory();
            var appenderFactory = new AppenderFactory(layoutFactory);

            for (int index = 0; index < appenderCount; index++)
            {
                string[] appenderArgs = Console.ReadLine().Split();

                string appenderType    = appenderArgs[0];
                string layoutType      = appenderArgs[1];
                string reportLevelType = "INFO";

                if (appenderArgs.Length == 3)
                {
                    reportLevelType = appenderArgs[2];
                }

                IAppender appender = appenderFactory.CreateAppender(appenderType, reportLevelType, layoutType);
                appenders[index] = appender;
            }

            ILogger logger = new Logger(appenders);

            return(logger);
        }
        private static void ParseAppendersInput(int appendersCount, ICollection <IAppender> appenders)
        {
            AppenderFactory appenderFactory = new AppenderFactory();

            for (int i = 0; i < appendersCount; i++)
            {
                string[] appendersArguments = Console.ReadLine()
                                              .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                              .ToArray();

                string appenderType = appendersArguments[0];
                string layoutType   = appendersArguments[1];
                string level        = "INFO";

                if (appendersArguments.Length == 3)
                {
                    level = appendersArguments[2];
                }

                try
                {
                    IAppender appender = appenderFactory.ProduceAppender(appenderType, layoutType, level);

                    appenders.Add(appender);
                }
                catch (ArgumentException argumentException)
                {
                    Console.WriteLine(argumentException.Message);
                }
            }
        }
Пример #9
0
        static ILogger InitializeLogger()
        {
            ICollection <IAppender> appenders       = new List <IAppender>();
            LayoutFactory           layoutFactory   = new LayoutFactory();
            AppenderFactory         appenderFactory = new AppenderFactory(layoutFactory);

            int numberOfAppenders = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfAppenders; i++)
            {
                var args = Console.ReadLine().Split();

                string appenderType = args[0];
                string layoutType   = args[1];
                string errorLevel   = "INFO";
                if (args.Length == 3)
                {
                    errorLevel = args[2];
                }

                IAppender appender = appenderFactory.GenerateAppender(appenderType, errorLevel, layoutType);
                appenders.Add(appender);
            }

            ILogger logger = new Models.Loggers.Logger(appenders);

            return(logger);
        }
Пример #10
0
        static void Main(string[] args)
        {
            AppenderFactory appenderFactory = new AppenderFactory();
            LayoutFactory   layoutFactory   = new LayoutFactory();
            Engine          engine          = new Engine(layoutFactory, appenderFactory);

            engine.Run();
        }
Пример #11
0
        private static void Main(string[] args)
        {
            IFactory <IAppender> appenderFactory = new AppenderFactory <IAppender>();
            IFactory <ILayout>   layoutFactory   = new LayoutFactory <ILayout>();
            IEngine engine = new Engine(appenderFactory, layoutFactory);

            engine.Run();
        }
Пример #12
0
        static void Main(string[] args)
        {
            ILayoutFactory   layoutFactory   = new LayoutFactory();
            IAppenderFactory appenderFactory = new AppenderFactory();

            IEngine engine = new Engine(new ConsoleReader(), appenderFactory, layoutFactory);

            engine.Run();
        }
Пример #13
0
        public static void Main()
        {
            IReader reader = new Reader();
            IWriter writer = new Writer();

            LayoutFactory   layoutFactory   = new LayoutFactory();
            AppenderFactory appenderFactory = new AppenderFactory();

            Controller controller = new Controller(layoutFactory, appenderFactory);
            Engine     engine     = new Engine(reader, writer, controller);

            engine.Run();
        }
Пример #14
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();
        }
Пример #15
0
        static void Main()
        {
            var numberOfApenders = int.Parse(Console.ReadLine());
            ICollection <IAppender> appenders      = new List <IAppender>();
            AppenderFactory         apenderFactory = new AppenderFactory();

            ReadAppendersData(numberOfApenders, appenders, apenderFactory);

            ILogger logger = new Models.Logger(appenders);

            var engine = new Engine(logger);

            engine.Run();
        }
Пример #16
0
        static void Main(string[] args)
        {
            var appendersCount  = int.Parse(Console.ReadLine());
            var appenderFactory = new AppenderFactory();

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

            ParseAppendersInput(appendersCount, appenderFactory, appenders);

            var logger = new Logger.Models.Logger(appenders);

            var engine = new Engine(logger);

            engine.Run();
        }
        public static void Main()
        {
            var appendersCount = int.Parse(Console.ReadLine());

            var appenders       = new List <IAppender>();
            var layoutFactory   = new LayoutFactory();
            var logFileFactory  = new LogFileFactory();
            var appenderFactory = new AppenderFactory(layoutFactory, logFileFactory);

            ReadAppendersData(appendersCount, appenders, appenderFactory);

            var logger = new Logger(appenders);

            var errorFactory = new ErrorFactory();

            var engine = new Engine(logger, errorFactory);

            engine.Run();
        }
Пример #18
0
        private static void RunLastPart()
        {
            var n         = int.Parse(Console.ReadLine());
            var appenders = new List <IAppender>();

            for (int i = 0; i < n; i++)
            {
                var input    = Console.ReadLine().Split();
                var layout   = LayoutFactory.GetInstance(input[1]);
                var appender = AppenderFactory.GetInstance(input[0], layout);
                if (input.Length > 2)
                {
                    var reportLevel = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input[2].ToLower());
                    appender.ReportLevel = (ReportLevel)Enum.Parse(typeof(ReportLevel), reportLevel);
                }
                appenders.Add(appender);
            }

            var    logger = new Loger(appenders);
            string command;

            while ((command = Console.ReadLine()) != "END")
            {
                if (command != null)
                {
                    var tokens = command.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    var loggerMethod = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tokens[0].ToLower());
                    var methodType   = typeof(Loger).GetMethod(loggerMethod);
                    methodType.Invoke(logger, new object[] { tokens[1], tokens[2] });
                }
            }

            Console.WriteLine(@"Logger info");
            foreach (IAppender appender in appenders)
            {
                Console.WriteLine($"Appender type: {appender.GetType().Name}, Layout type: {appender.Layout.GetType().Name}, Report level: {appender.ReportLevel.ToString().ToUpper()}, Messages appended: {appender.File.MessageNumber}, File size {appender.File.Size}");
            }
        }
Пример #19
0
        public static void Main()
        {
            //ILayout simpleLayout = new SimpleLayout();
            //IAppender consoleAppender = new ConsoleAppender(simpleLayout);
            //ILogger logger = new Models.Logger(consoleAppender);

            //logger.Error("3/26/2015 2:08:11 PM", "Error parsing JSON.");
            //logger.Info("3/26/2015 2:08:11 PM", "User Pesho successfully registered.");

            // **********************************************

            //ILayout simpleLayout = new SimpleLayout();
            //IAppender consoleAppender = new ConsoleAppender(simpleLayout);

            //IFile file = new LogFile();
            ////file.Write(simpleLayout, ErrorFactory.Create("Fatal",
            ////    DateTime.Now.ToString(ProjectConstants.DATETIME_FORMAT,CultureInfo.InvariantCulture),
            ////    "Super fatality happened!"));
            //IAppender fileAppender = new FileAppender(simpleLayout, file);

            //ILogger logger = new Models.Logger(consoleAppender, fileAppender);
            //logger.Error("3/26/2015 2:08:11 PM", "Error parsing JSON.");
            //logger.Info("3/26/2015 2:08:11 PM", "User Pesho successfully registered.");

            // **********************************************

            //ILayout xmlLayout = new XmlLayout();
            //ILayout simpleLayout = new SimpleLayout();
            //IAppender consoleAppender = new ConsoleAppender(simpleLayout);

            //IFile file = new LogFile();
            //IAppender fileAppender = new FileAppender(xmlLayout, file);

            //ILogger logger = new Models.Logger(consoleAppender, fileAppender);

            //logger.Fatal("3/31/2015 5:23:54 PM", "mscorlib.dll does not respond");
            //logger.Critical("3/31/2015 5:23:54 PM", "No connection string found in App.config");

            // **********************************************

            //var simpleLayout = new SimpleLayout();
            //var consoleAppender = new ConsoleAppender(simpleLayout);
            //consoleAppender.ReportLevel = Level.Error;

            //var logger = new Models.Logger(consoleAppender);

            //logger.Info("3/31/2015 5:33:07 PM", "Everything seems fine");
            //logger.Warning("3/31/2015 5:33:07 PM", "Warning: ping is too high - disconnect imminent");
            //logger.Error("3/31/2015 5:33:07 PM", "Error parsing request");
            //logger.Critical("3/31/2015 5:33:07 PM", "No connection string found in App.config");
            //logger.Fatal("3/31/2015 5:33:07 PM", "mscorlib.dll does not respond");

            // **********************************************

            //var layout = new SimpleLayout();
            //var xmlLayout = new XmlLayout();

            //var file = new LogFile();
            //var fileAppender = new FileAppender(layout, file);

            //var logger = new Models.Logger(fileAppender);
            //logger.Error("3/31/2015 5:33:07 PM", "Error parsing request");
            //Console.WriteLine(file.Size);

            // **********************************************

            int appendersCount = int.Parse(Console.ReadLine());

            IAppender[] appenders = new IAppender[appendersCount];
            for (int i = 0; i < appendersCount; i++)
            {
                string[] appenderArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                switch (appenderArgs.Length)
                {
                // "<appender type> <layout type> <REPORT LEVEL>"
                case 2:
                    appenders[i] = AppenderFactory.Create(appenderArgs[1], appenderArgs[0]);
                    break;

                case 3:
                    appenders[i] = AppenderFactory.Create(appenderArgs[1], appenderArgs[0], appenderArgs[2]);
                    break;
                }
            }

            var logger = new Models.Logger(appenders);

            CommandInterpreter.Run(logger);

            Console.WriteLine(logger);
        }
Пример #20
0
        public void Run()
        {
            List <IAppender> appenders = new List <IAppender>();

            int counter = int.Parse(Console.ReadLine());

            for (int i = 0; i < counter; i++)
            {
                string[] inputInfo = Console.ReadLine()
                                     .Split(" ", StringSplitOptions.RemoveEmptyEntries);


                string      appenderType = inputInfo[0];
                string      layoutType   = inputInfo[1];
                ReportLevel reportLevel  = ReportLevel.INFO;

                if (inputInfo.Length > 2)
                {
                    reportLevel = Enum.Parse <ReportLevel>(inputInfo[2], true);
                }

                ILayout   layout   = LayoutFactory.CreateLayout(layoutType);
                IAppender appender = AppenderFactory.CreateAppender(appenderType, layout, reportLevel);

                appenders.Add(appender);
            }

            string input = Console.ReadLine();

            ILoggers loggers = new Loggers(appenders.ToArray());

            while (input != "END")
            {
                string[] inputInfo = input.Split("|");

                string loggerType = inputInfo[0];
                string date       = inputInfo[1];
                string message    = inputInfo[2];

                if (loggerType == "INFO")
                {
                    loggers.Info(date, message);
                }
                if (loggerType == "ERROR")
                {
                    loggers.Error(date, message);
                }
                if (loggerType == "WARNING")
                {
                    loggers.Warning(date, message);
                }
                if (loggerType == "CRITICAL")
                {
                    loggers.Critical(date, message);
                }
                if (loggerType == "FATAL")
                {
                    loggers.Fatal(date, message);
                }

                input = Console.ReadLine();
            }

            Console.WriteLine("Logger info");

            foreach (var appender1 in appenders)
            {
                Console.WriteLine(appender1);
            }
        }
Пример #21
0
 public Controller()
 {
     this.appenderFactory        = new AppenderFactory(AppendersNamespace);
     this.layoutFactory          = new LayoutFactory(LayoutsNamespece);
     this.writableObjectsFactory = new WritableObjectFactory(WritableObjectsNamespace);
 }
Пример #22
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);
        }
Пример #23
0
        private static IAppender[] ReadAllAppenders(IReader reader, LayoutFactory layoutFactory, AppenderFactory appenderFactory)
        {
            int N = int.Parse(reader.ReadLine());

            IAppender[] appenders = new IAppender[N];

            for (int i = 0; i < N; i++)
            {
                // "<appender type> <layout type> <REPORT LEVEL>"
                string[] appenderArgs = reader.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   type         = appenderArgs[0];
                string   layoutType   = appenderArgs[1];


                ILayout   layout   = layoutFactory.GetLayout(layoutType);
                IAppender appender = null;
                if (appenderArgs.Length == 3)
                {
                    string reportLevel = appenderArgs[2];
                    appender = appenderFactory.GetAppender(type, layout, reportLevel);
                }
                else
                {
                    appender = appenderFactory.GetAppender(type, layout);
                }

                appenders[i] = appender;
            }

            return(appenders);
        }
Пример #24
0
        public static void Main()
        {
            //ILayout simpleLayout = new SimpleLayout();
            //IAppender consoleAppender = new ConsoleAppender(simpleLayout);
            //ILogger logger = new Logger(consoleAppender);

            //logger.Error("3/26/2015 2:08:11 PM", "Error parsing JSON.");
            //logger.Info("3/26/2015 2:08:11 PM", "User Pesho successfully registered.");

            //var simpleLayout = new SimpleLayout();
            //var xmlLayout = new XmlLayout();
            //var consoleAppender = new ConsoleAppender(xmlLayout);

            //var file = new LogFile();
            //var fileAppender = new FileAppender(xmlLayout, file);

            //var logger = new Logger(consoleAppender, fileAppender);
            //logger.Error("3/26/2015 2:08:11 PM", "Error parsing JSON.");
            //logger.Info("3/26/2015 2:08:11 PM", "User Pesho successfully registered.");

            //var simpleLayout = new SimpleLayout();
            //var consoleAppender = new ConsoleAppender(simpleLayout);
            //consoleAppender.ReportLevel = ReportLevel.Error;

            //var file = new LogFile();
            //var fileAppender = new FileAppender(xmlLayout, file);
            //fileAppender.ReportLevel = ReportLevel.Fatal;

            //var logger = new Logger(consoleAppender, fileAppender);

            //logger.Info("3/31/2015 5:33:07 PM", "Everything seems fine");
            //logger.Warning("3/31/2015 5:33:07 PM", "Warning: ping is too high - disconnect imminent");
            //logger.Error("3/31/2015 5:33:07 PM", "Error parsing request");
            //logger.Critical("3/31/2015 5:33:07 PM", "No connection string found in App.config");
            //logger.Fatal("3/31/2015 5:33:07 PM", "mscorlib.dll does not respond");

            var     layoutFactory   = new LayoutFactory();
            var     appenderFactory = new AppenderFactory();
            IReader reader          = new ConsoleReader();

            IAppender[] appenders = ReadAllAppenders(reader, layoutFactory, appenderFactory);
            var         logger    = new Logger(appenders);

            var commandInterpreter = new CommandInterpreter(logger);
            var cmdFactory         = new CommandFactory();

            List <string[]> msgsArgs = ReadAllMessages(reader);

            foreach (var msgArgs in msgsArgs)
            {
                string reportLevel = msgArgs[0];
                string dateTime    = msgArgs[1];
                string msg         = msgArgs[2];

                ReportLevel level;
                if (!Enum.TryParse(reportLevel, true, out level))
                {
                    throw new ArgumentException("Invalid level!");
                }

                Command command = cmdFactory.GetCommand(level, dateTime, msg);
                commandInterpreter.Execute(command);
            }

            Console.WriteLine(logger);
        }