Created
April 16, 2012 11:27
-
-
Save mhafalir/2397900 to your computer and use it in GitHub Desktop.
ExecutionTimeLogger
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 ExecutionTimeLogger : IDisposable | |
| { | |
| public DateTime BeginTime { get; set; } | |
| public DateTime EndTime { get; set; } | |
| public double TotalMilliseconds { get; set; } | |
| public string Data { get; set; } | |
| public ExecutionTimeLogger(string data = "") | |
| { | |
| this.BeginTime = DateTime.Now; | |
| this.Data = data; | |
| } | |
| public void Dispose() | |
| { | |
| try | |
| { | |
| this.EndTime = DateTime.Now; | |
| this.TotalMilliseconds = (this.EndTime - this.BeginTime).TotalMilliseconds; | |
| SaveLog(); | |
| } | |
| catch { } | |
| } | |
| private void SaveLog() | |
| { | |
| // TODO: Save Log | |
| } | |
| } |
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 Program | |
| { | |
| static void Main() | |
| { | |
| using(new ExecutionTimeLogger("Program.Main")) | |
| { | |
| // Do Sth. | |
| System.Threading.Thread.Sleep(5000); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment