Example #1
0
        static void Main(string[] args)
        {
            ILayout simpleLayout = new SimpleLayout();
            IAppender consoleAppender = new ConsoleAppender(simpleLayout);

            var fileAppender = new FileAppender(simpleLayout);
            fileAppender.File = "../../log.txt";

            var logger = new Logger(consoleAppender, fileAppender);
            logger.Error("Error parsing JSON.");
            logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
            logger.Warn("Warning - missing files.");

            var xmlLayout = new XmlLayout();
            consoleAppender = new ConsoleAppender(xmlLayout);
            logger = new Logger(consoleAppender);
            logger.Fatal("mscorlib.dll does not respond");
            logger.Critical("No connection string found in App.config");

            consoleAppender = new ConsoleAppender(simpleLayout);
            consoleAppender.ReportLevel = ReportLevel.Error;
            logger = new Logger(consoleAppender);

            logger.Info("Everything seems fine");
            logger.Warn("Warning: ping is too high - disconnect imminent");
            logger.Error("Error parsing request");
            logger.Critical("No connection string found in App.config");
            logger.Fatal("mscorlib.dll does not respond");
        }
Example #2
0
        public static void Main()
        {
            var simpleLayout = new SimpleLayout();
            var consoleAppender = new ConsoleAppender(simpleLayout);
            consoleAppender.ReportLevel = ReportLevel.Error;

            var logger = new Logger(consoleAppender);

            logger.Info("Everything seems fine");
            logger.Warn("Warning: ping is too high - disconnect imminent");
            logger.Error("Error parsing request");
            logger.Critical("No connection string found in App.config");
            logger.Fatal("mscorlib.dll does not respond");
        }
Example #3
0
        public static void Main()
        {
            ILayout simpleLayout = new SimpleLayout();
            IDataAppender consoleAppender =
                 new ConsoleAppender(simpleLayout);
            ILogger logger = new Logger(consoleAppender);

            logger.Error("Error parsing JSON.");
            logger.Info($"User {"Pesho"} successfully registered.");

            var fileAppender = new FileAppender(simpleLayout, "log.txt");
            logger = new Logger(fileAppender);
            logger.Error("Error parsing JSON.");
            logger.Info($"User {"Pesho"} successfully registered.");
            logger.Warn("Warning - missing files.");
        }
        private static void RunThirdPart()
        {
            var appenders       = new List <IAppender>();
            var simpleLayout    = new SimpleLayout();
            var consoleAppender = new ConsoleAppender(simpleLayout);

            appenders.Add(consoleAppender);
            consoleAppender.ReportLevel = ReportLevel.Error;

            var logger = new Loger(appenders);

            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");
        }
        private static void RunFirstPart()
        {
            var appenders       = new List <IAppender>();
            var simpleLayout    = new SimpleLayout();
            var consoleAppender = new ConsoleAppender(simpleLayout);

            appenders.Add(consoleAppender);

            var file         = new LogFile();
            var fileAppender = new FileAppender(simpleLayout);

            appenders.Add(fileAppender);
            fileAppender.File = file;

            var logger = new Loger(appenders);

            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.");
        }
Example #6
0
        static void Main(string[] args)
        {
            //ILayout simpleLayout = new SimpleLayout();
            //IAppender consoleAppender =
            //     new ConsoleAppender(simpleLayout);
            //ILogger logger = new Logger(consoleAppender);

            //logger.Error("Error parsing JSON.");
            //logger.Info(string.Format("User {0} successfully registered.", "Pesho"));

            //var simpleLayout = new SimpleLayout();

            //var consoleAppender = new ConsoleAppender(simpleLayout);
            //var fileAppender = new FileAppender(simpleLayout);
            //fileAppender.File = "log.txt";

            //var logger = new Logger(consoleAppender, fileAppender);
            //logger.Error("Error parsing JSON.");
            //logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
            //logger.Warn("Warning - missing files.");

            //var xmlLayout = new XmlLayout();
            //var consoleAppender = new ConsoleAppender(xmlLayout);
            //var logger = new Logger(consoleAppender);

            //logger.Fatal("mscorlib.dll does not respond");
            //logger.Critical("No connection string found in App.config");

            var simpleLayout    = new SimpleLayout();
            var consoleAppender = new ConsoleAppender(simpleLayout);

            consoleAppender.ReportLevel = ReportLevel.Error;

            var logger = new Logger(consoleAppender);

            logger.Info("Everything seems fine");
            logger.Warn("Warning: ping is too high - disconnect imminent");
            logger.Error("Error parsing request");
            logger.Critical("No connection string found in App.config");
            logger.Fatal("mscorlib.dll does not respond");
        }
Example #7
0
        static void Main(string[] args)
        {
            ILayout layout = new SimpleLayout();
            IAppender consoleAppender = new ConsoleAppender(layout);
            IAppender fileAppender = new FileAppender(layout);

            ILogger logger = new Logger(consoleAppender, fileAppender);
            try
            {
                logger.Info("The program was finished just now");
                logger.Warn("I am going to test the program now");
                logger.Error("File not found");
            }
            catch (FileNotFoundException)
            {
                Logger currentLogger = logger as Logger;
                if (currentLogger != null)
                {
                    IAppender appender = currentLogger.FindAppender("ConsoleLogger");
                    appender.Append(new Message("Operation failed because the Path of file was not found", Type.Fatal));
                }
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            ILayout   layout          = new SimpleLayout();
            IAppender consoleAppender = new ConsoleAppender(layout);
            IAppender fileAppender    = new FileAppender(layout);

            ILogger logger = new Logger(consoleAppender, fileAppender);

            try
            {
                logger.Info("The program was finished just now");
                logger.Warn("I am going to test the program now");
                logger.Error("File not found");
            }
            catch (FileNotFoundException)
            {
                Logger currentLogger = logger as Logger;
                if (currentLogger != null)
                {
                    IAppender appender = currentLogger.FindAppender("ConsoleLogger");
                    appender.Append(new Message("Operation failed because the Path of file was not found", Type.Fatal));
                }
            }
        }
Example #9
0
        public static void Main()
        {
            try
            {
                var simpleLayout = new SimpleLayout();
                var xmlLayout    = new XmlLayout();

                IAppender consoleAppender = new ConsoleAppender(simpleLayout);
                IAppender fileAppender    = new FileAppender(simpleLayout);
                fileAppender.File = "../../log.txt";

                IAppender fileAppenderXml = new FileAppender(xmlLayout);
                fileAppenderXml.File = "../../log.xml";

                ILogger logger = new Logger(consoleAppender, fileAppender, fileAppenderXml);

                // add in logs
                logger.Error("Error parsing JSON.");
                logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
                logger.Warn("Warn - missing files.");
                logger.Fatal("mscorlib.dll does not respond");
                logger.Critical("No connection string found in App.config");

                logger.Info("Everything seems fine");
                logger.Warn("Warning: ping is too high - disconnect imminent");
                logger.Error("Error parsing request");
                logger.Critical("No connection string found in App.config");
                logger.Fatal("mscorlib.dll does not respond");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine();
        }
Example #10
0
        public static void Main()
        {
            var simpleLayout = new SimpleLayout();
            var jsonLayout   = new JsonLayout();

            // var myLayout = new SoftUniLayout();
            var consoleAppender = new ConsoleAppender(simpleLayout);

            consoleAppender.ReportLevel = ReportLevel.Error;
            consoleAppender.ReportLevel = ReportLevel.Error;
            var fileAppender = new FileAppendder(jsonLayout, "../../Log.txt");

            fileAppender.ReportLevel = ReportLevel.Error;
            var logger = new Logger(consoleAppender, fileAppender);

            logger.Error("Error parsing JSON.");
            logger.Warning("User John successfully registered");
            logger.Info("Everything seems fine");
            logger.Warning("Warning: ping is too high - disconnect imminent");
            logger.Error("Error parsing request");
            logger.Critical("No connection string found in App.config");
            logger.Fatal("mscorlib.dll does not respond");
            fileAppender.Close();
        }
Example #11
0
        public void Run(int count)
        {
            IAppender[] appenders = new IAppender[count];

            for (int i = 0; i < count; i++)
            {
                string[] token = Console.ReadLine().Split();

                ILayout layout = null;

                if (token[1] == nameof(SimpleLayout))
                {
                    layout = new SimpleLayout();
                }
                else if (token[1] == nameof(XmlLayout))
                {
                    layout = new XmlLayout();
                }

                IAppender appender = null;

                if (token[0] == nameof(ConsoleAppender))
                {
                    appender = new ConsoleAppender(layout);
                }
                else if (token[0] == nameof(FileAppender))
                {
                    appender = new FileAppender(layout);
                }

                if (token.Length == 3)
                {
                    Level level = (Level)Enum.Parse(typeof(Level), token[2]);
                    appender.Level = level;
                }

                appenders[i] = appender;
            }

            LoggerType logger = new LoggerType(appenders);

            string command = Console.ReadLine();

            while (command != "END")
            {
                string[] token = command.Split("|");

                Level level = (Level)Enum.Parse(typeof(Level), token[0]);

                switch (level)
                {
                case Level.CRITICAL:
                    logger.Critical(token[1], token[2]);
                    break;

                case Level.ERROR:
                    logger.Error(token[1], token[2]);
                    break;

                case Level.FATAL:
                    logger.Fatal(token[1], token[2]);
                    break;

                case Level.INFO:
                    logger.Info(token[1], token[2]);
                    break;

                case Level.WARNING:
                    logger.Warning(token[1], token[2]);
                    break;
                }
            }

            Console.WriteLine(logger);
        }
Example #12
0
        private static void AddAppenders(int n, IAppender[] appenders)
        {
            for (int i = 0; i < n; i++)
            {
                string[] args = Console.ReadLine().Split();

                IAppender appender     = null;
                string    appenderType = args[0];

                ILayout layout     = null;
                string  layoutType = args[1];

                ReportLevel reportLevel = ReportLevel.INFO;


                switch (layoutType.ToLower())
                {
                case "simplelayout":
                    layout = new SimpleLayout();
                    break;

                case "xmllayout":
                    layout = new XmlLayout();
                    break;

                default:
                    layout = null;
                    break;
                }

                switch (appenderType.ToLower())
                {
                case "consoleappender":
                    appender = new ConsoleAppender(layout);
                    break;

                case "fileappender":
                    appender = new FileAppender(layout, new LogFile());
                    break;

                default:
                    appender = null;
                    break;
                }

                if (args.Length == 3)
                {
                    switch (args[2].ToLower())
                    {
                    case "info":
                        reportLevel = ReportLevel.INFO;
                        break;

                    case "warning":
                        reportLevel = ReportLevel.WARNING;
                        break;

                    case "error":
                        reportLevel = ReportLevel.ERROR;
                        break;

                    case "critical":
                        reportLevel = ReportLevel.CRITICAL;
                        break;

                    case "fatal":
                        reportLevel = ReportLevel.FATAL;
                        break;

                    default:
                        reportLevel = ReportLevel.INFO;
                        break;
                    }
                }

                ((Appender)appender).ReportLevel = reportLevel;

                appenders[i] = appender;
            }
        }
Example #13
0
        public void Act(int countOfAppenders)
        {
            IAppender[] appenders = new IAppender[countOfAppenders];

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

                ILayout layout = null;

                switch (input[1])
                {
                case nameof(SimpleLayout):
                    layout = new SimpleLayout();
                    break;

                case nameof(XmlLayout):
                    layout = new XmlLayout();
                    break;

                default:
                    throw new ArgumentException();
                }

                IAppender appender = null;

                switch (input[0])
                {
                case nameof(ConsoleAppender):
                    appender = new ConsoleAppender(layout);
                    break;

                case nameof(FileAppender):
                    appender = new FileAppender(layout);
                    ((FileAppender)appender).File = new LogFile();
                    break;
                }

                if (input.Length == 3)
                {
                    ReportLevel level = (ReportLevel)Enum.Parse(typeof(ReportLevel), input[2]);
                    appender.ReportLevel = level;
                }

                appenders[i] = appender;
            }

            var logger = new Logger(appenders);


            string command;

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

                string time    = input[1];
                string message = input[2];

                ReportLevel level = (ReportLevel)Enum.Parse(typeof(ReportLevel), input[0]);

                switch (level)
                {
                case ReportLevel.CRITICAL:
                    logger.Critical(time, message);
                    break;

                case ReportLevel.ERROR:
                    logger.Error(time, message);
                    break;

                case ReportLevel.FATAL:
                    logger.Fatal(time, message);
                    break;

                case ReportLevel.INFO:
                    logger.Info(time, message);
                    break;

                case ReportLevel.WARNING:
                    logger.Warn(time, message);
                    break;
                }
            }

            Console.WriteLine(logger);
        }