Last active
December 19, 2015 08:18
-
-
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.
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 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); | |
| } | |
| } |
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
| 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