Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Created April 20, 2015 04:01
Show Gist options
  • Save danielmackay/c5f7a704217c4cad4769 to your computer and use it in GitHub Desktop.
Save danielmackay/c5f7a704217c4cad4769 to your computer and use it in GitHub Desktop.
Web API Exception Logger. #webapi
config.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger());
internal class TraceExceptionLogger : ExceptionLogger
{
private readonly Log _log;
public TraceExceptionLogger()
{
_log = new Log();
}
public override void Log(ExceptionLoggerContext context)
{
LogException(context);
base.Log(context);
}
private void LogException(ExceptionLoggerContext context)
{
var exception = context.Exception;
var uri = context.Request.RequestUri.ToString();
_log.WriteLog(LogLevel.Error, uri, exception.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment