示例#1
0
        public void Should_obtain_registration_before_logging()
        {
            log.Info("Test.");

            Received.InOrder(
                () =>
            {
                muxer.Register("logs/log", Arg.Any <FileLogSettings>(), Arg.Any <WeakReference>());
                muxer.TryAdd("logs/log", Arg.Any <LogEventInfo>(), Arg.Any <WeakReference>());
            });
        }
示例#2
0
        /// <inheritdoc />
        public void Log(LogEvent @event)
        {
            if (@event == null)
            {
                return;
            }

            if (!IsEnabledFor(@event.Level))
            {
                return;
            }

            while (true)
            {
                var settings     = settingsProvider.Get();
                var file         = filePathProvider.Get(settings);
                var registration = ObtainMuxerRegistration(file, settings);

                if (!muxer.TryAdd(file, new LogEventInfo(@event, settings), muxerHandleRef))
                {
                    eventsLost.Increment();
                    break;
                }

                if (registration.IsValid(file))
                {
                    break;
                }
            }
        }
示例#3
0
        public void TestSetup()
        {
            capturedEvents = new List <LogEvent>();

            registration = Substitute.For <IMuxerRegistration>();
            registration.IsValid("logs/log").Returns(true);

            muxer = Substitute.For <IMultiFileMuxer>();
            muxer.TryAdd(Arg.Any <FilePath>(), Arg.Do <LogEventInfo>(e => capturedEvents.Add(e.Event)), Arg.Any <WeakReference>()).Returns(true);
            muxer.Register(Arg.Any <FilePath>(), Arg.Any <FileLogSettings>(), Arg.Any <WeakReference>()).Returns(registration);

            settings = new FileLogSettings {
                FilePath = "logs/log", OutputTemplate = OutputTemplate.Parse("{Message}"), EnableFileLogSettingsCache = false
            };

            log = new FileLog(muxer, () => settings);
        }