I created a simple REST API with ASP.NET API. For testing purposes, I would like to add some traces. So I added NLog to my project. At the moment, my journal is as follows:
public void Post([FromBody]string value)
{
logger.Trace("Request: {0} api/values", Request.Method);
_repository.insert(value);
logger.Trace("Response: {0} api/values", Request.Method);
}
In each method, I added logger.Trace at the top and then at the bottom of my methods. I have 2 questions with this method:
- I should not add this line to each of my methods.
- I do not know how to add a JSON body to my trace
Point 1 is not a real problem at the moment (see below), but I need to quickly check something so that every JSON authority receives my API.
I already tried this
public void Post([FromBody]string value)
{
logger.Trace("Request: {0} api/values {1}", Request.Method, Request.Body);
_repository.insert(value);
logger.Trace("Response: {0} api/values", Request.Method);
}
But the request does not have a Body property.
1: http://weblogs.asp.net/fredriknormen/log-message-request-and-response-in-asp-net-webapi