Beispiel #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>());
            });
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private IMuxerRegistration ObtainMuxerRegistration(FilePath file, FileLogSettings settings)
        {
            var currentRegistration = muxerRegistration;

            if (currentRegistration != null && currentRegistration.IsValid(file))
            {
                return(currentRegistration);
            }

            lock (muxerRegistrationLock)
            {
                if (muxerRegistration != null && muxerRegistration.IsValid(file))
                {
                    return(muxerRegistration);
                }

                muxerRegistration?.Dispose();
                muxerRegistration = null;

                return(muxerRegistration = muxer.Register(file, settings, muxerHandleRef));
            }
        }