Created
April 20, 2015 04:01
-
-
Save danielmackay/c5f7a704217c4cad4769 to your computer and use it in GitHub Desktop.
Web API Exception Logger. #webapi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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