Skip to content

Instantly share code, notes, and snippets.

@erichexter
Last active December 19, 2015 08:18
Show Gist options
  • Select an option

  • Save erichexter/5924313 to your computer and use it in GitHub Desktop.

Select an option

Save erichexter/5924313 to your computer and use it in GitHub Desktop.
a timing api to log api calls to system trace. this is useful in windows azure website, since you can stream trace information from the infrastructure when you need to diagnose.
public class LoggingStopwatch : IDisposable
{
private readonly string _operationname;
private Stopwatch stopwatch;
public LoggingStopwatch(string operationname)
{
_operationname = operationname;
stopwatch = new Stopwatch();
System.Diagnostics.Trace.WriteLine("Starting tracing of "+ operationname);
stopwatch.Start();
}
public void Dispose()
{
stopwatch.Stop();
System.Diagnostics.Trace.WriteLine("Operation " +_operationname+" took " + stopwatch.Elapsed);
}
}
using (new LoggingStopwatch("call third part api xxxxxx"))
{
//call your slow third party api here
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment