Exemplo n.º 1
0
        public async Task ReconfigureAsyncOnLogfileWithExceptionInPreprocessorDispose_Should_DisposeOtherPreprocessorsAnyway()
        {
            var preprocessor         = new TestPreprocessor();
            var router               = new TestRouter <LogEvent <StandardLoglevel> >();
            var logfileConfiguration = (new LogfileConfigurationBuilder <StandardLoglevel>()
                                        .AddPreprocessor(preprocessor)
                                        .AddRouter(router)
                                        as LogfileConfigurationBuilder <StandardLoglevel>)
                                       .Build();
            var logfile = new Logfile <StandardLoglevel>();
            await logfile.ReconfigureAsync(logfileConfiguration, default);

            ((TestPreprocessor)logfile.Configuration.Preprocessors.OfType <TestPreprocessor>().First()).DisposeCallback =
                () => throw new InvalidOperationException();
            var preprocessorDisposed = false;

            ((TestPreprocessor)logfile.Configuration.Preprocessors.OfType <TestPreprocessor>().Last()).DisposeCallback =
                () => preprocessorDisposed = true;
            var newRouter = new TestRouter <LogEvent <StandardLoglevel> >();
            var newLogfileConfiguration = (new LogfileConfigurationBuilder <StandardLoglevel>()
                                           .AddRouter(newRouter)
                                           as LogfileConfigurationBuilder <StandardLoglevel>)
                                          .Build();
            await logfile.ReconfigureAsync(newLogfileConfiguration, default);

            preprocessorDisposed.Should().BeTrue();
            logfile.Configuration.Should().BeSameAs(newLogfileConfiguration);
        }
Exemplo n.º 2
0
        public async Task ReconfigureAsyncOnLogfile_Should_DisposeOldPreprocessorsAndRoutersAndReplaceConfiguration()
        {
            var preprocessor         = new TestPreprocessor();
            var router               = new TestRouter <LogEvent <StandardLoglevel> >();
            var logfileConfiguration = (new LogfileConfigurationBuilder <StandardLoglevel>()
                                        .AddPreprocessor(preprocessor)
                                        .AddRouter(router)
                                        as LogfileConfigurationBuilder <StandardLoglevel>)
                                       .Build();
            var logfile = new Logfile <StandardLoglevel>();
            await logfile.ReconfigureAsync(logfileConfiguration, default);

            var preprocessorDisposed = false;

            ((TestPreprocessor)logfile.Configuration.Preprocessors.OfType <TestPreprocessor>().Single()).DisposeCallback =
                () => preprocessorDisposed = true;
            var routerDisposed = false;

            ((TestRouter <LogEvent <StandardLoglevel> >)logfile.Configuration.Routers.Single()).DisposeCallback =
                () => routerDisposed = true;
            var newRouter = new TestRouter <LogEvent <StandardLoglevel> >();
            var newLogfileConfiguration = (new LogfileConfigurationBuilder <StandardLoglevel>()
                                           .AddRouter(newRouter)
                                           as LogfileConfigurationBuilder <StandardLoglevel>)
                                          .Build();
            await logfile.ReconfigureAsync(newLogfileConfiguration, default);

            preprocessorDisposed.Should().BeTrue();
            routerDisposed.Should().BeTrue();
            logfile.Configuration.Should().BeSameAs(newLogfileConfiguration);
        }
Exemplo n.º 3
0
        public void LogDeveloperEventWhileEnabled_Should_ForwardEvent()
        {
            var router = new TestRouter <LogEvent <StandardLoglevel> >();
            var logfileConfiguration = (new LogfileConfigurationBuilder <StandardLoglevel>()
                                        .EnableDeveloperMode()
                                        .AddRouter(router)
                                        as LogfileConfigurationBuilder <StandardLoglevel>)
                                       .Build();
            var logfile = new Logfile <StandardLoglevel>();

            logfile.ReconfigureAsync(logfileConfiguration, default).GetAwaiter().GetResult();

            var forwarded = new ManualResetEventSlim();
            LogEvent <StandardLoglevel> forwardedEvent = null;

            router.ForwardCallback = (_logEvents) =>
            {
                forwardedEvent = _logEvents.Single();
                forwarded.Set();
            };
            var event1 = new LogEvent <StandardLoglevel>(_ => { }, StandardLoglevel.Warning).Developer;

            logfile.Log(new LogEvent <StandardLoglevel>[] { event1 });

            event1.IsDeveloper.Should().BeTrue();
            forwarded.Wait(TimeSpan.FromMilliseconds(500)).Should().BeTrue();
            forwardedEvent.Should().BeSameAs(event1);
        }
Exemplo n.º 4
0
        void prepare(out Logfile <StandardLoglevel> logfile, out TestRouter <LogEvent <StandardLoglevel> > router)
        {
            router = new TestRouter <LogEvent <StandardLoglevel> >();
            var logfileConfiguration = (new LogfileConfigurationBuilder <StandardLoglevel>()
                                        .AddRouter(router)
                                        as LogfileConfigurationBuilder <StandardLoglevel>)
                                       .Build();

            logfile = new Logfile <StandardLoglevel>();
            logfile.ReconfigureAsync(logfileConfiguration, default).GetAwaiter().GetResult();
        }
Exemplo n.º 5
0
        public async Task AddLogEvent_Should_LogThisLogEventAutomaticallyAfterTheLogEventContainingTheExceptionDetails()
        {
            // Arrange
            var logfileConfigurationBuilder = new LogfileConfigurationBuilder <StandardLoglevel>();

            logfileConfigurationBuilder
            .AddPreprocessor(ExtractLogEventsFromExceptions <StandardLoglevel> .Instance);

            var logfile = new Logfile <StandardLoglevel>();
            await logfile.ReconfigureAsync(logfileConfigurationBuilder.Build(), default);

            var exception = new InvalidOperationException();

            // Act
            var logEvent = ExceptionDataExtensions.AddLogEvent(
                exception,
                StandardLoglevel.Warning);

            // Assert
            exception.Data[typeof(LogEvent <StandardLoglevel>)].Should().BeSameAs(logEvent);
        }