Beispiel #1
0
 private void AppendMessage(string date, ReportLevelEnum reportLevel, string message)
 {
     foreach (IAppender appender in this.appenders)
     {
         appender.Append(date, reportLevel, message);
     }
 }
Beispiel #2
0
        private IAppender AppenderCreator(string appenderType, ILayout layout, ReportLevelEnum reportLevel)
        {
            IAppender appender = null;

            switch (appenderType)
            {
            case nameof(ConsoleAppender):

                appender = new ConsoleAppender(layout)
                {
                    ReportLevel = reportLevel
                };

                break;

            case nameof(FileAppender):

                appender = new FileAppender(layout, new LogFile())
                {
                    ReportLevel = reportLevel
                };

                break;
            }

            return(appender);
        }
Beispiel #3
0
 private void AppendAll(string date, ReportLevelEnum reportLevelEnum, string message)
 {
     foreach (var appender in Appenders)
     {
         appender.Append(date, reportLevelEnum, message);
     }
 }
Beispiel #4
0
        public void Run()
        {
            int n = int.Parse(Console.ReadLine());

            IAppender[] appenders = new IAppender[n];

            for (int i = 0; i < n; i++)
            {
                string[] appendersParts = Console.ReadLine()
                                          .Split(" ");

                string appenderType = appendersParts[0];
                string layoutType   = appendersParts[1];

                ReportLevelEnum reportLevel = appenders.Length == 3
                    ? Enum.Parse <ReportLevelEnum>(appendersParts[2], true)
                    : ReportLevelEnum.Info;

                ILayout layout = LayoutCreator(layoutType);

                IAppender appender = AppenderCreator(appenderType, layout, reportLevel);

                appenders[i] = appender;
            }

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] tokens = input.Split('|');

                string reportLevel = tokens[0];
                string date        = tokens[1];
                string message     = tokens[2];

                ILogger logger = new Loggers.Logger(appenders);

                switch (reportLevel.ToLower())
                {
                case "info": logger.Info(date, message); break;

                case "warning": logger.Warning(date, message); break;

                case "error": logger.Error(date, message); break;

                case "critical": logger.Critical(date, message); break;

                case "fatal": logger.Fatal(date, message); break;
                }
            }

            Console.WriteLine("Logger info");

            foreach (var appender in appenders)
            {
                Console.WriteLine(appender.ToString());
            }
        }
Beispiel #5
0
        public override void Append(string date, ReportLevelEnum reportLevel, string message)
        {
            if (reportLevel < ReportLevel)
            {
                return;
            }

            MessageCount++;
            string content = string.Format(Layout.Template, date, reportLevel, message);

            LogFile.Write(content);
        }
Beispiel #6
0
 public abstract void Append(string date, ReportLevelEnum reportLevel, string message);