public void BuildWithAllowedAndBlockedLoglevels_Should_CreatePreprocessor()
        {
            var builder = new LogfileConfigurationBuilder <StandardLoglevel>();

            builder.AllowLoglevels.Add(StandardLoglevel.Warning);
            builder.AllowLoglevels.Add(StandardLoglevel.Error);
            builder.AllowLoglevels.Add(StandardLoglevel.Critical);
            builder.BlockLoglevels.Add(StandardLoglevel.Error);

            var logfileConfiguration = builder.Build();

            var loglevelFilter = (LoglevelFilter <StandardLoglevel>)logfileConfiguration.Preprocessors.Single();

            loglevelFilter.Process(new LogEvent <StandardLoglevel>((_logEvent) => { }, StandardLoglevel.Warning)).Should().BeNull();
            loglevelFilter.Process(new LogEvent <StandardLoglevel>((_logEvent) => { }, StandardLoglevel.Error)).Should().BeEmpty();
        }
        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);
        }
        public void Build_Should_CreateHubConfiguration()
        {
            var router1       = new TestRouter <LogEvent <StandardLoglevel> >();
            var preprocessor1 = new TestPreprocessor();
            var builder       = new LogfileConfigurationBuilder <StandardLoglevel>();

            builder.AllowLoglevels.Add(StandardLoglevel.Warning);
            builder.BlockLoglevels.Add(StandardLoglevel.Error);
            builder.Routers.Add(router1);
            builder.Preprocessors.Add(preprocessor1);
            builder.MaximumRoutableQueueLength          = 1;
            builder.MaximumRoutablesForwardingCount     = 2;
            builder.WaitForMoreRoutablesForwardingDelay = TimeSpan.FromMilliseconds(3);

            var logfileConfiguration = builder.Build();

            logfileConfiguration.Routers.Should().Contain(router1);
            logfileConfiguration.Preprocessors.Should().Contain(preprocessor1);
            logfileConfiguration.MaximumRoutablesQueueLength.Should().Be(1);
            logfileConfiguration.MaximumRoutablesForwardingCount.Should().Be(2);
            logfileConfiguration.WaitForMoreRoutablesForwardingDelay.Should().Be(TimeSpan.FromMilliseconds(3));
            logfileConfiguration.Preprocessors.OfType <LoglevelFilter <StandardLoglevel> >().Single();
        }