Skip to content

Instantly share code, notes, and snippets.

@jmbeach
Last active March 9, 2021 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmbeach/7f0a8a9371e72e8f5f73e3b6470fb6a4 to your computer and use it in GitHub Desktop.
Save jmbeach/7f0a8a9371e72e8f5f73e3b6470fb6a4 to your computer and use it in GitHub Desktop.
Log body of requests in ServiceStack using attribute
public class RequestDataSpyAttribute : RequestFilterAttribute
{
// gets injected by ServiceStack
public ILog Log { get; set; }
private readonly string _logMessage;
public RequestDataSpyAttribute(string logMessage)
{
_logMessage = logMessage;
}
public override void Execute(IRequest req, IResponse res, object requestDto)
{
System.Web.HttpRequestWrapper original = req.OriginalRequest as System.Web.HttpRequestWrapper;
if (original == null)
return;
Log.Debug($"{_logMessage} Request: {original.InputStream.ReadToEnd()}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment