Ejemplo n.º 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");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var formatter = new XmlFormatter();
            var appender = new ConsoleAppender(formatter);
            var logger = new Logger(appender);

            logger.Info("This is app");
            logger.Error("Cannot be empty!");
            logger.Critical("You are illigle");
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
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));
                }
            }
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            var simpleLayout = new SimpleLayout();

            var consoleAppender = new ConsoleAppender(simpleLayout);
            var fileAppender    = new FileAppender(simpleLayout)
            {
                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");

            simpleLayout                = new SimpleLayout();
            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");
        }
Ejemplo n.º 6
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));
                }
            }
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {

            Console.Write(typeof(string).Assembly.ImageRuntimeVersion);
            Console.ReadKey();

            ////////////// LOGGER ////////////////////


            /************ CONSOLE *******************/

            // 1. Get a LoggerManager
            LoggerManager loggerManager = new LoggerManager();

            //// 2. Create a new Logger
            ILogger myLogger = loggerManager.CreateLogger();

            ////3. Log
            myLogger.Log("Hello World !");

            /************ CONSOLE with custom log pattern *******************/

            ////////////// TESTS 1 ////////////////////

            ILogger myLogger2 = loggerManager.CreateLogger("testLogger");

            string myPattern = LogElements.LOGGER_NAME.StrRef() + " / " + LogElements.MESSAGE.StrRef() + " / " + LogElements.TIMESTAMP.StrRef();

            ConsoleAppender myConsoleApp = (ConsoleAppender)myLogger2.AddAppender(AppenderType.CONSOLE);

            myConsoleApp.Layout = myPattern;

            myLogger2.Error("Salut les gens ;)");

            ////////////// TESTS 2 ////////////////////

            /************ Not log if log level lower than logger level *******************/

            ILogger myLogger3 = loggerManager.CreateLogger("testLogger3");
            myLogger3.Level = Level.ERROR;

            myLogger3.Trace("Un nouveau log"); // doesn't log

            ////////////// TESTS 3 ////////////////////

            /************ Duplicate Log **************/

            ILogger myLogger4 = loggerManager.CreateLogger("testLogger4");
            myLogger4.Level = Level.DEBUG;

            myLogger4.Warn("Un warn log");

            ILogger myLogger4_2 = loggerManager.DuplicateLogger("testLogger4");

            myLogger4_2.Warn("Un warn log dupliqué");


            //string myLogger4Name = myLogger4.Name;
            //string myLogger4Parent = myLogger4.Parent;
            //Console.WriteLine(myLogger4Name);
            //Console.WriteLine("Parent : " + myLogger4Parent);

            //string myLogger4_2Name = myLogger4_2.Name;
            //string myLogger4_2Parent = myLogger4_2.Parent;
            //Console.WriteLine(myLogger4_2Name);
            //Console.WriteLine("Parent : " + myLogger4_2Parent);

            ////////////// TESTS 5 ////////////////////

            /************ MESSAGE BOX **************/

            ILogger myLogger5 = loggerManager.CreateLogger("testLogger5");

            MessageBoxAppender myConsoleApp5 = (MessageBoxAppender)myLogger5.AddAppender(AppenderType.MESSAGE_BOX);

            ModalBox myBox = new ModalBox(LogElements.LOGGER_NAME.StrRef());

            myConsoleApp5.Box = myBox;

            myLogger5.Warn("Bonjour !");

            ////////////// TESTS 6 ////////////////////

            /************ MESSAGE BOX **************/

            ILogger myLogger6 = loggerManager.CreateLogger("testLogger6");

            MessageBoxAppender myConsoleApp6 = (MessageBoxAppender)myLogger6.AddAppender(AppenderType.MESSAGE_BOX);

            string captionPattern = LogElements.TIMESTAMP.StrRef() + " - " + LogElements.LEVEL.StrRef();

            ModalBox myBox2 = new ModalBox(captionPattern, MessageBoxIcon.Error);
            myBox2.Buttons = MessageBoxButtons.OKCancel;
            myBox2.SetAction(DialogResult.OK, () => Console.WriteLine("Anne"));



            myConsoleApp6.Box = myBox2;

            myLogger6.Error("Bonjour !");
            //myLogger6.Trace("Bonjour Trace !");
            //myLogger6.Debug("Bonjour Debug !");
            //myLogger6.Info("Bonjour info !");
            //myLogger6.Warn("Bonjour warn !");


            ////////////// TESTS 7 ////////////////////

            /************ TOAST **************/

            ToastAppender mytoastApp6 = (ToastAppender)myLogger6.AddAppender(AppenderType.TOAST);

            string ligne1 = LogElements.TIMESTAMP.StrRef("T") + " - " + LogElements.LOGGER_NAME.StrRef();
            string ligne2 = LogElements.MESSAGE.StrRef();

            ToastLayout toastLay = new ToastLayout(ligne1, ligne2);

            mytoastApp6.ToastLayout = toastLay;

            myLogger6.Error("Bonjour Bonjour!");

            myLogger6.Error("Bonjour Hello!");



            ////////////// TESTS 8 ////////////////////

            /************ DATABASE **************/

            // Database information

            MySqlDatabase dbSettings = DatabaseFactory.MySqlDb.Set
                                                      .DatabaseName("logDb")
                                                      .Server("localhost")
                                                      .UserId("root").ToMySqlDatabase;

            // Create a logger
            ILogger myLog = loggerManager.CreateLogger("myLog");

            // Create a database Appender (correspond à une base de donnée)
            DataBaseAppender myDbApp = (DataBaseAppender)myLog.AddAppender(AppenderType.DATABASE);
            myDbApp.AttachDB(dbSettings);

            myLog.Error("Game Modeler !");

            ////////////// TESTS 8 ////////////////////

            /************ MESSAGE_BOX_CUSTOM with Xaml file **************/

            // Create a logger
            ILogger myLogger7 = loggerManager.CreateLogger("testLogger7");
            // Create a database Appender (correspond à une base de donnée)

            IAppender myMBCApp = myLogger7.AddAppender(AppenderType.MESSAGE_BOX_CUSTOM, typeof(MessageBoxCustom));

            myLogger7.Error("Game Modeler !");

            myLogger7.Error("Game Modeler 2!");

            ////////////// TESTS 9 ////////////////////

            /************ FILE APPENDER **************/

            var myFileApp = (FileAppender)myLogger7.AddAppender(AppenderType.FILE);

            myFileApp.Set.Name("testLoggerXml")
                         .Path(@"C:\Users\")
                         .Type(FileAppenderType.TEXT);

            myLogger7.Error("test du logger");

            myLogger7.Info("deuxième log");
        }
Ejemplo n.º 11
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;
            }
        }
Ejemplo n.º 12
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);
        }