Exemple #1
0
        // 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();
            }
        }
Exemple #3
0
        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");
        }
Exemple #4
0
 public void Should_show_output_in_test_run()
 {
     FormatLoggerAccessor.Locate().Error($"An error");
 }