// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { ConfigureWebApi(appBuilder); appBuilder.Use(async(env, next) => { FormatLoggerAccessor.Locate().Debug($"{env.Request.Method} {env.Request.Path}"); await next(); FormatLoggerAccessor.Locate().Debug($"Response code: {env.Response.StatusCode}"); }); // StructureMap: // config.DependencyResolver = ServiceLocator.Get<StructureMapWebApiDependencyResolver>(); // Elmah // config.Services.Add(typeof(IExceptionLogger), new ElmahWebApi2ExceptionLogger()); // Make ./public the default root of the static files in our Web Application. //app.UseFileServer(new FileServerOptions //{ // RequestPath = new PathString(string.Empty), // FileSystem = new PhysicalFileSystem("./public"), // EnableDirectoryBrowsing = true, //}); }
private static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs e) { FormatLoggerAccessor.Locate().Error("Global exception handler error", (Exception)e.ExceptionObject); if (Debugger.IsAttached) { Debugger.Break(); } }
public override void OnException(HttpActionExecutedContext actionExecutedContext) { var content = AsyncHelper.RunSync(() => actionExecutedContext.Request.Content.ReadAsStringAsync()); FormatLoggerAccessor.Locate().Error(actionExecutedContext.Exception, $"\r\n{actionExecutedContext.Request.Method} {actionExecutedContext.Request.RequestUri}\r\n" + $"{actionExecutedContext.Request.Headers.ToLogString()}" + $" {content}\r\n"); }
public void Should_show_output_in_test_run() { FormatLoggerAccessor.Locate().Error($"An error"); }