예제 #1
0
        public void AddAppender(string appenderInfo)
        {
            var data = appenderInfo.Split(" ");

            var appenderType = data[0];
            var layoutType   = data[1];

            var layout = layoutFactory.GetLayout(layoutType);

            //Since the input doesn't provide information for the console or the file, the default for this project will be used
            //which will break the Liskov principle, but this should be rather here than in the Appender classes.
            IAppender appender = null;

            if (appenderType == "ConsoleAppender")
            {
                var writableObject = writableObjectsFactory.GetWritableObject("Console");
                appender = appenderFactory.GetAppender(appenderType, layout, writableObject);
            }

            else if (appenderType == "FileAppender")
            {
                var writableObject = writableObjectsFactory.GetWritableObject("LogFile");
                appender = appenderFactory.GetAppender(appenderType, layout, writableObject);
            }

            if (data.Length > 2 && Enum.TryParse(data[2], true, out ReportLevels reportLevelLimit))
            {
                appender.ReportLevel = reportLevelLimit;
            }

            if (logger is null)
            {
                logger = new Loggers.Logger(appender);
            }

            else
            {
                logger.AddAppenders(appender);
            }
        }