Ejemplo n.º 1
0
        public void ChildLoggerInheritsParentLevelByDefault()
        {
            var sink = new CollectingSink();

            var logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Logger(lc => lc
                    .WriteTo.Sink(sink))
                .CreateLogger();

            logger.Write(Some.DebugEvent());

            Assert.Equal(1, sink.Events.Count);
        }
Ejemplo n.º 2
0
        public void ChildLoggerCanOverrideInheritedLevel()
        {
            var sink = new CollectingSink();

            var logger = new LoggerConfiguration()
                .MinimumLevel.ControlledBy(new LoggingLevelSwitch(LogEventLevel.Debug))
                .WriteTo.Logger(lc => lc
                    .MinimumLevel.Error()
                    .WriteTo.Sink(sink))
                .CreateLogger();

            logger.Write(Some.DebugEvent());

            Assert.Equal(0, sink.Events.Count);
        }
        public void ModifyingCopiesPassedThroughTheSinkPreservesOriginal()
        {
            var secondary = new CollectingSink();
            var secondaryLogger = new LoggerConfiguration()
                .WriteTo.Sink(secondary)
                .CreateLogger();

            var e = Some.InformationEvent();
            new LoggerConfiguration()
                .WriteTo.Logger(secondaryLogger)
                .CreateLogger()
                .Write(e);
            
            Assert.AreNotSame(e, secondary.SingleEvent);
            var p = Some.LogEventProperty();
            secondary.SingleEvent.AddPropertyIfAbsent(p);
            Assert.IsTrue(secondary.SingleEvent.Properties.ContainsKey(p.Name));
            Assert.IsFalse(e.Properties.ContainsKey(p.Name));
        }
Ejemplo n.º 4
0
        public void LowerMinimumLevelOverridesArePropagated()
        {
            var sink = new CollectingSink();

            var logger = new LoggerConfiguration()
                .MinimumLevel.Error()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
                .WriteTo.Sink(sink)
                .CreateLogger();

            logger.Write(Some.InformationEvent());
            logger.ForContext(Serilog.Core.Constants.SourceContextPropertyName, "Microsoft.AspNet.Something").Write(Some.InformationEvent());
            logger.ForContext<LoggerConfigurationTests>().Write(Some.InformationEvent());

            Assert.Equal(1, sink.Events.Count);
        }
Ejemplo n.º 5
0
        public void LevelSwitchTakesPrecedenceOverMinimumLevel()
        {
            var sink = new CollectingSink();

            var logger = new LoggerConfiguration()
                .WriteTo.Sink(sink, LogEventLevel.Fatal, new LoggingLevelSwitch())
                .CreateLogger();

            logger.Write(Some.InformationEvent());

            Assert.Equal(1, sink.Events.Count);
        }
Ejemplo n.º 6
0
        public void LastMinimumLevelConfigurationWins()
        {
            var sink = new CollectingSink();

            var logger = new LoggerConfiguration()
                .MinimumLevel.ControlledBy(new LoggingLevelSwitch(LogEventLevel.Fatal))
                .MinimumLevel.Debug()
                .WriteTo.Sink(sink)
                .CreateLogger();

            logger.Write(Some.InformationEvent());

            Assert.Equal(1, sink.Events.Count);
        }