Last active
March 9, 2021 18:43
-
-
Save jmbeach/7f0a8a9371e72e8f5f73e3b6470fb6a4 to your computer and use it in GitHub Desktop.
Log body of requests in ServiceStack using attribute
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
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