Example #1
0
        private static List <IAppender> CreateAppenders()
        {
            var appenders       = new List <IAppender>();
            var layoutFactory   = new LayoutFactory();
            var appenderFactory = new AppenderFactory();

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

            for (int i = 0; i < appendCount; i++)
            {
                var tokens       = Console.ReadLine().Split();
                var appenderType = tokens[0];
                var layoutType   = tokens[1];
                var errorStr     = "INFO";

                if (tokens.Length == 3)
                {
                    errorStr = tokens[2];
                }

                ILayout   layout   = layoutFactory.Create(layoutType);
                IAppender appender = appenderFactory.Create(layout, errorStr, appenderType);

                appenders.Add(appender);
            }

            return(appenders);
        }
        public IAppender Build()
        {
            var consoleAppender = new ConsoleAppender {
                Layout = LayoutFactory.Create()
            };

            consoleAppender.ActivateOptions();
            return(consoleAppender);
        }
        public IAppender Build()
        {
            var fileAppender = new RollingFileAppender();

            fileAppender.RollingStyle      = RollingFileAppender.RollingMode.Date;
            fileAppender.DatePattern       = "'.'yyyyMMdd'.txt'";
            fileAppender.File              = File();
            fileAppender.StaticLogFileName = false;
            fileAppender.Layout            = LayoutFactory.Create();
            fileAppender.ActivateOptions();

            return(fileAppender);
        }
Example #4
0
        public void Run()
        {
            int         numOfAppenders = int.Parse(Console.ReadLine());
            string      appenderType   = string.Empty;
            string      layoutType     = string.Empty;
            ReportLevel reportLevel    = 0;

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

            var appenders = new List <IAppender>();

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

                appenderType = lines[0];
                layoutType   = lines[1];

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

                var layout   = layoutFactory.Create(layoutType);
                var appender = appenderFactory.Create(appenderType, layout, reportLevel);
                appenders.Add(appender);
                reportLevel = 0;
            }

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                var messages = input.Split("|");

                reportLevel = Enum.Parse <ReportLevel>(messages[0]);
                var    date    = DateTime.ParseExact(messages[1], "M/dd/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
                string message = messages[2];

                var error  = new Error(date, reportLevel, message);
                var logger = new Logger(appenders);
                logger.Log(error);
            }

            var logFile = new LogFile();

            Console.WriteLine("Logger info");
            logFile.Write(appenders);
        }
Example #5
0
        public void CreateAppender(string input)
        {
            string[]    appenderInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
            string      appenderType = appenderInfo[0];
            string      layoutType   = appenderInfo[1];
            ReportLevel reportLevel  = ReportLevel.INFO;

            try
            {
                if (appenderInfo.Length == 3)
                {
                    reportLevel = Enum.Parse <ReportLevel>(appenderInfo[2]);
                }

                ILayout   layout   = LayoutFactory.Create(layoutType);
                IAppender appender = AppenderFactory.Create(appenderType, layout);
                appender.ReportLevel = reportLevel;
                appenders.Add(appender);
            }
            catch (Exception argEx)
            {
                Console.WriteLine(argEx.Message);
            }
        }