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)); }); }
public void RequestLoggingMiddleware_Inject_CallsLogger() { //Arrange var ctx = new OwinContext { Request = { Scheme = LibOwin.Infrastructure.Constants.Https, Path = new PathString("/logtest"), Method = "GET" } }; //ctx.Request.Headers.Add("TestHeader", new[] {"TestHeaderValue"}); var loggerMock = new Mock <ILogger>(); loggerMock.Setup(logger => logger.ForContext <RequestLoggingMiddleware>()).Returns(() => loggerMock.Object); loggerMock.Setup(logger => logger.Information(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>(), It.IsAny <object>())).Verifiable(); loggerMock.Setup(logger => logger.Information(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <object>())).Verifiable(); //Act var pipeline = RequestLoggingMiddleware.Inject(_noOp, loggerMock.Object); pipeline(ctx.Environment); //Assert loggerMock.Verify(); }