コード例 #1
0
 protected LogLevelResolver ReadLogPattern(XmlScanner scanner)
 {
     return(LogLevelResolvers.LogMatches(
                LogMatchers.NameMatchesPattern(
                    scanner.Text().Trim()),
                scanner.GetAttributeAsEnum <LogLevel>(
                    typeof(LogLevel),
                    "level",
                    true)));
 }
コード例 #2
0
        /*
         * Appenderパイプラインの例
         */
        protected void AppenderPipeline()
        {
            Tee            tee;
            FormatAppender formatter;

            this.LogManager.Appender =
                new Synchronized(
                    new Tee(
                        new ConsoleAppender(),
                        new NullAppender()));
            tee = (Tee)this.LogManager.Appender.Unwrap(typeof(Tee));
            if (tee == null)
            {
                this.Log.Fatal("failed on unwrap tee");
                return;
            }
            formatter = (FormatAppender)tee[0].Unwrap(typeof(FormatAppender));
            if (formatter != null)
            {
                formatter.MessageFormat = "Appender#0 {Timestamp:yyyy-MM-dd'T'HH:mm:dd.fff} {LevelName,-7} {SourceName} {Message}{NewLine}{Causes}";
            }
            this.Log.Notice("ConsoleAppender and NullAppender");

            /*
             * Appender#0 2013-11-11T13:12:11.901 NOTICE  At.Pkgs.Logging.Sample.Program ConsoleAppender and NullAppender
             */
            tee[1] = new Filter(
                new ConsoleAppender(),
                LogEntityMatchers.And(
                    LogEntityMatchers.LevelHigherThan(LogLevel.Notice),
                    LogEntityMatchers.SourceMatches(
                        LogMatchers.NameMatchesPattern("At.Pkgs.Logging.Sample.*"))));
            formatter = (FormatAppender)tee[1].Unwrap(typeof(FormatAppender));
            if (formatter != null)
            {
                formatter.MessageFormat = "Appender#1 {Timestamp:yyyy-MM-dd'T'HH:mm:dd.fff} {LevelName,-7} {SourceName} {Message}{NewLine}{Causes}";
            }
            foreach (Appender appender in tee)
            {
                formatter = (FormatAppender)appender.Unwrap(typeof(FormatAppender));
                if (formatter == null)
                {
                    this.Log.Fatal("failed on unwap formatter");
                }
                else
                {
                    this.Log.Notice("message format: {0}", formatter.MessageFormat);
                }
            }

            /*
             * Appender#0 2013-11-11T13:12:11.904 NOTICE  At.Pkgs.Logging.Sample.Program message format: Appender#0 {Timestamp:yyyy-MM-dd'T'HH:mm:dd.fff} {LevelName,-7} {SourceName} {Message}{NewLine}{Causes}
             * Appender#0 2013-11-11T13:12:11.905 NOTICE  At.Pkgs.Logging.Sample.Program message format: Appender#1 {Timestamp:yyyy-MM-dd'T'HH:mm:dd.fff} {LevelName,-7} {SourceName} {Message}{NewLine}{Causes}
             */
            this.Log.Notice("single appender");

            /*
             * Appender#0 2013-11-11T13:12:11.906 NOTICE  At.Pkgs.Logging.Sample.Program single appender
             */
            this.Log.Error("multiple appenders");

            /*
             * Appender#0 2013-11-11T13:12:11.906 ERROR   At.Pkgs.Logging.Sample.Program multipul appenders
             * Appender#1 2013-11-11T13:12:11.906 ERROR   At.Pkgs.Logging.Sample.Program multipul appenders
             */
        }
コード例 #3
0
        /*
         * LogLevelの制御もLogごとに動的に変更可能
         *
         * パターンについて:
         * '*'は'.'を含む0個以上の文字にマッチ
         * '-'は'.'を含まない0個以上の文字にマッチ
         *
         * Rule/LogMatchers.And, Or, Not等を使用して複雑な条件も指定可能
         */
        protected void LogLevelResolver()
        {
            Log a;
            Log b;
            List <LogLevelResolver> resolvers;

            a         = this.LogManager.LogFor("At.Pkgs.Logging.Sample.SomeAction");
            b         = this.LogManager.LogFor("Jp.Architector.Sample.MoreAction");
            resolvers = new List <LogLevelResolver>();
            this.Log.Notice("normal");
            a.Debug("ng");
            b.Debug("ng");

            /*
             * 2013-11-11T13:12:11.894 NOTICE  At.Pkgs.Logging.Sample.Program normal
             */
            this.Log.Notice("set Debug for all(*)");
            resolvers.Add(LogLevelResolvers.LogMatches(
                              LogMatchers.NameMatchesPattern("*"),
                              LogLevel.Debug));
            this.LogManager.Update(resolvers.ToArray());
            a.Debug("ok");
            b.Debug("ok");

            /*
             * 2013-11-11T13:12:11.894 NOTICE  At.Pkgs.Logging.Sample.Program set Debug for all(*)
             * 2013-11-11T13:12:11.896 DEBUG   At.Pkgs.Logging.Sample.SomeAction ok
             * 2013-11-11T13:12:11.897 DEBUG   Jp.Architector.Sample.MoreAction ok
             */
            this.Log.Notice("set Notice for Jp.Architector.*");
            resolvers.Add(LogLevelResolvers.LogMatches(
                              LogMatchers.NameMatchesPattern("Jp.Architector.*"),
                              LogLevel.Notice));
            this.LogManager.Update(resolvers.ToArray());
            a.Debug("ok");
            b.Debug("ng");

            /*
             * 2013-11-11T13:12:11.897 NOTICE  At.Pkgs.Logging.Sample.Program set Notice for Jp.Architector.*
             * 2013-11-11T13:12:11.897 DEBUG   At.Pkgs.Logging.Sample.SomeAction ok
             */
            this.Log.Notice("set Trace for *Action");
            resolvers.Add(LogLevelResolvers.LogMatches(
                              LogMatchers.NameMatchesPattern("*Action"),
                              LogLevel.Trace));
            this.LogManager.Update(resolvers.ToArray());
            a.Trace("ok");
            b.Trace("ok");
            this.Log.Trace("ng");

            /*
             * 2013-11-11T13:12:11.897 NOTICE  At.Pkgs.Logging.Sample.Program set Trace for *Action
             * 2013-11-11T13:12:11.898 TRACE   At.Pkgs.Logging.Sample.SomeAction ok
             * 2013-11-11T13:12:11.898 TRACE   Jp.Architector.Sample.MoreAction ok
             */
            this.Log.Notice("set Debug for *.-reAction");
            resolvers.Add(LogLevelResolvers.LogMatches(
                              LogMatchers.NameMatchesPattern("*.-reAction"),
                              LogLevel.Debug));
            this.LogManager.Update(resolvers.ToArray());
            a.Trace("ok");
            b.Trace("ng");
            this.Log.Trace("ng");

            /*
             * 2013-11-11T13:12:11.898 NOTICE  At.Pkgs.Logging.Sample.Program set Debug for *.-reAction
             * 2013-11-11T13:12:11.899 TRACE   At.Pkgs.Logging.Sample.SomeAction ok
             */
        }