Ejemplo n.º 1
0
        static void Main()
        {
            //Init dependencies
            ILayout layout = new XmlLayout();
            IAppender fileAppender = new FileAppender(layout, "file.txt");
            IAppender consoleAppender = new ConsoleAppender(layout);
            Logger logger = new Logger(consoleAppender);

            //shows every report level above ReportLevel.Warn
            consoleAppender.ReportLevel = ReportLevel.Fatal;

            logger.Critical("Critical Sample Report");
            logger.Fatal("Fatal Sample Report");
            logger.Info("Info Sample Report");
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            var simpleFormatter = new SimpleFormatter();
            var xmlFormatter = new XmlFormatter();
            // Create own formatter
            var jsonFormatter = new JsonFormatter();

            var fileAppender = new FileAppender(jsonFormatter, "log.txt");
            var consoleAppender = new ConsoleAppender(xmlFormatter);
            // Create own appender
            var sqlAppender = new SqlAppender(jsonFormatter);

            Logger logger = new Logger(consoleAppender, fileAppender);

            logger.Critical("Out of memory");
            logger.Info("Unused local variable 'name'");

            fileAppender.Close();
        }
Ejemplo n.º 3
0
        static void Main()
        {
            // Introduce custom formatter
            IFormatter formatter = new CrazyFormatter();

            FileAppender appender = new FileAppender("file.txt", formatter);
            Logger logger = new Logger(appender);

            try
            {
                logger.Critical("a cannot be 5");
                logger.Critical("Out of memory");
                // CauseException();
                logger.Info("Unused local variable 'name'");
            }
            finally
            {
                appender.Close();
            }
        }