Hello,
I just herited of a very bad Web API code in C#. I need to improve it but I don't know where to start. There are plenty f classes and the code is a nightmare.I'm also sure that part of this code is never used.
I would like to count the number of time each request is called and what time each request take. I would like to log all my result in a table. In one or two days I could have a clear view of what I the most used and what take time. Client are complaining about that.
I use Nlog for log and a simple Stopwatch to calculation of performance. What do you suggest? I know it's better to use Filter and attribute for traces but how can I log and trace performance like this?
What I have tried:
Here is a sample of my API:
public Item GetItem(string id)
{
logger.Trace(string.Format("Request: GET api/Item/{0}", id));
Stopwatch sw = new Stopwatch();
sw.Start();
Item item = context.Items.Single(i => i.Code == id);
sw.Stop();
logger.Trace(string.Format("Response: GET api/values/{0}\r\nElpased={1}\r\rn{2}", id, sw.Elapsed, response));
Thanks to
http://weblogs.asp.net/fredriknormen/log-message-request-and-response-in-asp-net-webapi
http://stackoverflow.com/q/969290/196526