Пример #1
0
        public void PerformanceLoggingMiddleware_Inject_RecordsPerfLogs()
        {
            //Arrange
            var ctx = new OwinContext
            {
                Request =
                {
                    Scheme = LibOwin.Infrastructure.Constants.Https,
                    Path   = new PathString("/logtest"),
                    Method = "GET"
                }
            };

            var loggerMock = new Mock <ILogger>();

            loggerMock.Setup(logger => logger.ForContext <PerformanceLoggingMiddleware>()).Returns(() => loggerMock.Object);
            loggerMock.Setup(logger => logger.Information(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>(), It.IsAny <Int64>())).Verifiable();

            //Act
            var pipeline = PerformanceLoggingMiddleware.Inject(_noOp, loggerMock.Object);

            pipeline(ctx.Environment);

            loggerMock.Verify();
        }
Пример #2
0
        public void Configure(IApplicationBuilder app)
        {
            var appConfig = new AppConfiguration();

            _config.Bind(appConfig);

            Console.WriteLine("Configuring with EnableAuthorization=" + appConfig.EnableAuthorization);

            var levelSwitch = new LoggingLevelSwitch();
            var log         = ConfigureLogger(levelSwitch, appConfig);

            app.UseCors("default");
            app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority            = appConfig.Authority,
                RequireHttpsMetadata = false,

                ApiName = appConfig.ClientId,
            });

            app.UseOwin(buildFunc =>
            {
                buildFunc(next => GlobalErrorLoggingMiddleware.Inject(next, log));
                buildFunc(CorrelationTokenMiddleware.Inject);
                buildFunc(next => RequestLoggingMiddleware.Inject(next, log));
                buildFunc(next => PerformanceLoggingMiddleware.Inject(next, log));
                buildFunc(next => new DiagnosticsMiddleware(next, levelSwitch).Inject);
                buildFunc(next => new MonitoringMiddleware(next, HealthCheck).Inject);
                if (appConfig.EnableAuthorization)
                {
                    buildFunc.UseAuthPlatform(appConfig.Scopes.Split(','));
                }
                buildFunc.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(log, appConfig));
            });
        }