コード例 #1
0
 protected LogLevelResolver ReadLogPattern(XmlScanner scanner)
 {
     return(LogLevelResolvers.LogMatches(
                LogMatchers.NameMatchesPattern(
                    scanner.Text().Trim()),
                scanner.GetAttributeAsEnum <LogLevel>(
                    typeof(LogLevel),
                    "level",
                    true)));
 }
コード例 #2
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
             */
        }