Пример #1
0
        private static void ExampleOne()
        {
            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"));
        }
Пример #2
0
        private static void ExampleTwo()
        {
            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.");
        }
Пример #3
0
        private static void ExampleFour()
        {
            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");
        }
Пример #4
0
        private static void Main(string[] args)
        {
            ILayout simpleLayout = new SimpleLayout();
            
            //this is a client created layout implemented in the current project
            ILayout xmLayout = new XmLlayout();

            IAppender consoleAppender = new ConsoleAppender(simpleLayout);
            consoleAppender.ReportLevel = EntryLevel.Critical;

            IFileAppender fileAppender = new FileAppender(xmLayout);
            fileAppender.ReportLevel = EntryLevel.Info;
            fileAppender.File = "..\\..\\log.xml";

            ILogger logger = new Logger(consoleAppender, fileAppender);

            // NOTE: I have redesigned the logger class so that we can easily 
            // add additional levels of warnings (Debug for instance) without the need to edit the Logger class
            // Also I added a functionality to turn logging 'on' and 'off' without the need to comment or delete
            // existing logger.Log lines. Default value is 'on'.

            logger.IsLogging = false;

            logger.Log(EntryLevel.Info, "This is just an info message.");
            logger.Log(EntryLevel.Warning, "This is a warning.");
            logger.Log(EntryLevel.Error, "Error parsing JSON.");
            logger.Log(EntryLevel.Critical, "Situation is critical!");
            logger.Log(EntryLevel.Fatal, "Just Give Up");

            logger.IsLogging = true;

            logger.Log(EntryLevel.Info, "This is just an info message.");
            logger.Log(EntryLevel.Warning, "This is a warning.");
            logger.Log(EntryLevel.Error, "Error parsing JSON.");
            logger.Log(EntryLevel.Critical, "Situation is critical!");
            logger.Log(EntryLevel.Fatal, "Just Give Up");
        }