// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { var log = ConfigureLogger(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // app.UseOwin(x => x.UseNancy()); app.UseOwin(buildFunc => { /* * buildFunc(next => GlobalErrorLogging.Middleware(next, log)); * buildFunc(next => CorrelationToken.Middleware(next)); * buildFunc(next => RequestLogging.Middleware(next, log)); * buildFunc(next => PerformanceLogging.Middleware(next, log)); * buildFunc(next => new MonitoringMiddleware(next, HealthCheck).Invoke); * buildFunc.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(log)); */ buildFunc(next => CorrelationToken.Middleware(next)); buildFunc(next => RequestLogging.Middleware(next, log)); buildFunc.UseNancy(); }); }
public void Enable_Should_LogError_For_Application() { var browser = new Browser(new ConfigurableBootstrapper(config => { config.ApplicationStartup((container, pipelines) => { RequestLogging.Enable(pipelines, _requestLogger.Object); }); config.Module <TestModule>(); })); Assert.Throws <Exception>(() => browser.Get("/test/error", config => { config.HostName("localhost"); config.HttpRequest(); config.Header("Accept", "text/html"); })); _requestLogger.Verify(x => x.LogError( It.Is <RequestData>(r => r.Url == new Uri("http://localhost/test/error") && r.HttpMethod == "GET" && r.Header.ContainsKey("Accept") && r.Header["Accept"].Any(y => y.Contains("text/html")) && r.Content.Length == 0), It.Is <ResponseData>(r => r.StatusCode == 0 && r.ReasonPhrase == null && r.Header.Count == 0 && r.Content.Length == 0), It.Is <Exception>(ex => ex.Message == "ERROR")), Times.Once); }
public void Enable_Should_Log_DELETE_Request_For_Application() { var browser = new Browser(new ConfigurableBootstrapper(config => { config.ApplicationStartup((container, pipelines) => { RequestLogging.Enable(pipelines, _requestLogger.Object); }); config.Module <TestModule>(); })); browser.Delete("/test", config => { config.HostName("localhost"); config.HttpRequest(); config.Header("Accept", "text/html"); }); _requestLogger.Verify(x => x.Log( It.Is <RequestData>(r => r.Url == new Uri("http://localhost/test") && r.HttpMethod == "DELETE" && r.Header.ContainsKey("Accept") && r.Header["Accept"].Any(y => y.Contains("text/html")) && r.Content.Length == 0), It.Is <ResponseData>(r => r.StatusCode == 200 && r.ReasonPhrase == "OK" && r.Header.ContainsKey("X-Test") && r.Header["X-Test"][0] == "TEST" && r.Content.SequenceEqual(Encoding.UTF8.GetBytes("TEST")))), Times.Once); }
public void Configure(IApplicationBuilder app) { var log = ConfigureLogger(); app.UseOwin(buildFunc => { buildFunc(next => GlobalErrorLogging.Middleware(next, log)); buildFunc(next => CorrelationToken.Middleware(next)); buildFunc(next => RequestLogging.Middleware(next, log)); buildFunc(next => PerformanceLogging.Middleware(next, log)); buildFunc(next => new MonitoringMiddleware(next, HealthCheck).Invoke); buildFunc.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(log)); }); }
public void Configure(IApplicationBuilder app) { System.Net.ServicePointManager.DefaultConnectionLimit = 1024; ConfigurationBinder.Bind(Configuration.GetSection("ImageServer"), Conf); app.UseOwin(buildFunc => { buildFunc(next => RequestId.Middleware(next)); buildFunc(next => SizeConstraints.Middleware(next)); buildFunc(next => RequestLogging.Middleware(next, Log)); buildFunc(next => PerformanceLogging.Middleware(next, Log)); buildFunc(next => new MonitoringMiddleware(next, HealthCheckAsync).InvokeAsync); buildFunc.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(Conf, Log, httpClient)); }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseCors("Cors"); Logger log = ConfigurationLogger(); app.UseOwin(buildFunc => { buildFunc(next => GlobalErrorLogging.Middleware(next, log)); buildFunc(next => CorrelationToken.Middleware(next)); buildFunc(next => RequestLogging.Middleware(next, log)); buildFunc(next => PerformanceLogging.Middleware(next, log)); buildFunc(next => new MonitoringMiddleware(next, HealthCheck).Invoke); buildFunc.UseNancy(opt => opt.Bootstrapper = new CustomBootstrapper()); }); }
public void Log_each_incoming_request_and_each_outgoing_response() { using (TestCorrelator.CreateContext()) { AppFunc pipelineFunc(AppFunc next) => RequestLogging.Middleware(next, m_Logger); var ctx = SetupOwinTestEnvironment("/test"); var pipeline = pipelineFunc(m_NoOp); var env = ctx.Environment; pipeline(env); var msgs = TestCorrelator.GetLogEventsFromCurrentContext(); msgs.Should().NotBeEmpty().And.HaveCount(2); var reqLogMsg = msgs.First(); reqLogMsg.Level.Should().Be(LogEventLevel.Information); reqLogMsg.RenderMessage().Should().Be("Incoming request: \"GET\", PathString { Value: \"/test\", HasValue: True }, []"); var resLogMsg = msgs.Last(); resLogMsg.Level.Should().Be(LogEventLevel.Information); resLogMsg.RenderMessage().Should().Be("Outgoing response: 200, []"); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment envi) { var log = ILoggerFactory.ConfigureLogger(); app.UseOwin(buildFunc => // let's you use OWIN with ASP.NET Core { buildFunc(next => CorrelationToken.Middleware(next)); buildFunc(next => // buildFunc builds an OWIN pipeline from MidFunc env => { var context = new OwinContext(env); var method = context.Request.Method; var path = context.Request.Path; System.Console.WriteLine($"Got Request lambdas: {method} {path}"); return(next(env)); }); buildFunc(next => new ConsoleMiddleware(next).Invoke); buildFunc(next => RequestLogging.Middleware(next, log)); buildFunc(next => PerformanceLogging.Middleware(next, log)); buildFunc(next => new MonitoringMiddleware(next, ShoppingCart.Library.Stores.ShoppingCartStore.HealthCheck).Invoke); //buildFunc.UseNancy(); // this uses the default parameterless Nancy bootstrapper buildFunc.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(log)); }); }
public TestWithLoggerModule(IRequestLogger requestLogger) { RequestLogging.Enable(this, requestLogger); }
public void Enable_When_RequestLogger_IsNull_ShouldThrow_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable(new Pipelines(), null)); Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable(new ConfigurableNancyModule(), null)); }
public void Enable_When_Pipelines_IsNull_ShouldThrow_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable((IPipelines)null, _requestLogger.Object)); Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable((NancyModule)null, _requestLogger.Object)); }