Beispiel #1
0
        static void Main()
        {
            var logger = new ReloadableLogger(cfg => cfg.WriteTo.Console());

            Log.Logger = logger;

            Log.Information("Starting up");

            var programLogger = Log.ForContext <Program>();

            try
            {
                programLogger.Information("Hello, world!");

                logger.Reload(cfg => cfg
                              .MinimumLevel.Override("ConsoleExample", LogEventLevel.Error)
                              .WriteTo.Console(theme: AnsiConsoleTheme.Code));

                // Level override now excludes this...
                programLogger.Information("Hello, again... maybe?");

                Log.Logger = logger.Freeze();

                throw new InvalidOperationException("That's all, folks.");
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Unhandled exception");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #2
0
        public void AFrozenLoggerYieldsSerilogLoggers()
        {
            var logger     = new ReloadableLogger(_ => _);
            var contextual = logger.ForContext <ReloadableLoggerTests>();

            var nested = contextual.ForContext("test", "test");

            Assert.IsNotType <Core.Logger>(nested);

            logger.Freeze();

            nested = contextual.ForContext("test", "test");
            Assert.IsType <Core.Logger>(nested);
        }