Created
October 21, 2015 12:36
-
-
Save wwwlicious/a560b5e5aa65c29e7222 to your computer and use it in GitHub Desktop.
ServicestackExceptionEnricher for Serilog
This file contains 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
namespace Logging | |
{ | |
using Serilog.Core; | |
using Serilog.Events; | |
using ServiceStack.ServiceClient.Web; | |
public class ServiceStackExceptionEnricher : ILogEventEnricher | |
{ | |
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | |
{ | |
var exception = logEvent.Exception as WebServiceException; | |
if (exception == null) return; | |
var errorCode = propertyFactory.CreateProperty("ErrorCode", exception.ErrorCode, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(errorCode); | |
var errorMessage = propertyFactory.CreateProperty("ErrorMessage", exception.ErrorMessage, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(errorMessage); | |
var responseBody = propertyFactory.CreateProperty("ResponseBody", exception.ResponseBody, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(responseBody); | |
var responseDto = propertyFactory.CreateProperty("ResponseDto", exception.ResponseDto, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(responseDto); | |
var responseStatus = propertyFactory.CreateProperty("ResponseStatus", exception.ResponseStatus, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(responseStatus); | |
var serverStackTrace = propertyFactory.CreateProperty("ServerStackTrace", exception.ServerStackTrace, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(serverStackTrace); | |
var statusCode = propertyFactory.CreateProperty("StatusCode", exception.StatusCode, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(statusCode); | |
var statusDescription = propertyFactory.CreateProperty("StatusDescription", exception.StatusDescription, destructureObjects: true); | |
logEvent.AddPropertyIfAbsent(statusDescription); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment