コード例 #1
0
        public static void NormalTest()
        {
            using var context = new LoggerContext();

            var app1 = new FalseAppender();
            var app2 = new FalseAppender();

            context.AddAppender("app1", app1);
            context.AddAppender("app2", app2);

            context.AddCategory("cat1");
            context.AddCategory("cat2");
            context.AddCategory("cat3");

            context.Connect("cat1", "app1");
            context.Connect("cat1", "app2", Filters.AcceptFilter, Filters.DenyFilter);
            context.Connect("cat2", "app2", Filters.AcceptFilter);
            context.Connect("cat2", "app1", Filters.Threshold(Logger.LevelWarn));
            context.Connect("cat3", "app1", Filters.Threshold(Logger.LevelWarn, Logger.LevelFatal));
            context.Connect("cat3", "app2", (level, category, content) => content.Length > 32);

            var log1 = context.GetLogger("cat1");
            var log2 = context.GetLogger("cat2");
            var log3 = context.GetLogger("cat3");

            Assert.Null(context.GetLogger("cat4"));

            log1.Trace("cat1:trace");
            log1.Debug("cat1:debug");
            log1.Info("cat1:info");
            log2.Debug("cat2:DEBUG");
            log2.Info("cat2:INFO");
            log2.Warn("cat2:WARN");
            log3.Info("cat3:info");
            log3.Warn("cat3:warn");
            log3.Error("cat3:7xError,7xError,7xError,7xError,7xError,7xError,7xError");
            log3.Fatal("cat3:7xFatal,7xFatal,7xFatal,7xFatal,7xFatal,7xFatal,7xFatal");
            log1.Log(4396, "level4396");

            app1.Assert(Logger.LevelTrace, "cat1", "cat1:trace");
            app1.Assert(Logger.LevelDebug, "cat1", "cat1:debug");
            app1.Assert(Logger.LevelInfo, "cat1", "cat1:info");
            app1.Assert(Logger.LevelWarn, "cat2", "cat2:WARN");
            app1.Assert(Logger.LevelWarn, "cat3", "cat3:warn");
            app1.Assert(Logger.LevelError, "cat3", "cat3:7xError,7xError,7xError,7xError,7xError,7xError,7xError");
            app1.Assert(4396, "cat1", "level4396");
            app1.AssertEnd();

            app2.Assert(Logger.LevelDebug, "cat2", "cat2:DEBUG");
            app2.Assert(Logger.LevelInfo, "cat2", "cat2:INFO");
            app2.Assert(Logger.LevelWarn, "cat2", "cat2:WARN");
            app2.Assert(Logger.LevelError, "cat3", "cat3:7xError,7xError,7xError,7xError,7xError,7xError,7xError");
            app2.Assert(Logger.LevelFatal, "cat3", "cat3:7xFatal,7xFatal,7xFatal,7xFatal,7xFatal,7xFatal,7xFatal");
            app1.AssertEnd();
        }
コード例 #2
0
ファイル: ExceptionFilter.cs プロジェクト: vebin/AceSaaS
        public override void OnException(ExceptionContext context)
        {
            var ex     = context.Exception.GetException();
            var logger = LoggerContext.GetLogger(context.ActionDescriptor.DisplayName);

            logger.LogError(ex, "Execute with exception!!!");

            base.OnException(context);
        }
コード例 #3
0
ファイル: ActionAttribute.cs プロジェクト: vebin/AceSaaS
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);

            // log here
            var logger = LoggerContext.GetLogger(context.ActionDescriptor.DisplayName);

            logger.LogDebug($"Execute WebApi action \"{Name}\" with \"{context.ActionDescriptor.DisplayName}\"");
        }
コード例 #4
0
        public static int Main(string[] args)
        {
            using var loggerContext = new LoggerContext();

            loggerContext.AddCategory("default");
            loggerContext.AddAppender("console", new ColoredConsoleAppender());
            loggerContext.AddAppender("file", new StreamAppender(new FileStream("1.log", FileMode.Append, FileAccess.Write)));
            // loggerContext.AddAppender("console-layout", new ColoredConsoleAppender(new AmazingColorLayout()));
            loggerContext.Connect("default", "console");
            loggerContext.Connect("default", "file", Filters.Threshold(Logger.LevelError));
            // loggerContext.Connect("default", "console-layout", Filters.AcceptFilter);
            var logger = loggerContext.GetLogger("default");

            logger.Info($"cwd: {Environment.CurrentDirectory}");
            logger.Info("printing assemblies...");

            var ass = Assembly.GetExecutingAssembly();

            AssemblyPrinter.PrintAssembly(ass);
            AssemblyPrinter.PrintReferencedAssembly(ass);

            logger.Fatal("fatal");
            logger.Error("error");
            logger.Warn("warn");
            logger.Info("info");
            logger.Debug("debug");
            logger.Trace("trace");

            var x = from i in new[] { 1, 2, 3, 4, 5 } select i * 2 + 1;

            var o = CommandLineParser <O> .Parse(new[] { "-a", "1233", "-h", "--hh" }, (err, result) => {
                logger.Warn($"{err}");
                return(true);
            });

            Console.WriteLine(o.A);
            Console.WriteLine(o.B);

            var a = JsonParser.Parse("{ \"123\": [ 1, 2, 4, false, \"狗粮\" ], \"456\": [ true, null, \"レモン\" ] }");

            Console.Write(a.ToString(JsonStringifyOption.Compact | JsonStringifyOption.Inline | JsonStringifyOption.AsciiOnly));
            Console.WriteLine("###");
            Console.Write(a.ToString(JsonStringifyOption.AsciiOnly));
            Console.WriteLine("###");

            return(0);
        }