Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to logging unhandled exceptions in ASP.NET Web API 2 running on Azure Web Apps
public class ExceptionLoggerTraceRedirector : ExceptionLogger
public override void Log(ExceptionLoggerContext context)
var logtext = new StringBuilder();
logtext.AppendLine($"Request: {context.Request}").AppendLine();
logtext.AppendLine($"Exception: {context.Exception}");
public static class WebApiConfig
public static void Register(HttpConfiguration config)
// Web API configuration and services
config.Services.Replace(typeof(IExceptionLogger), new ExceptionLoggerTraceRedirector());
// Web API routes
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment