From a44420e81d411063fe69a2a88ae8e7bd6d28ba70 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Tue, 14 Dec 2021 18:49:30 +0000 Subject: [PATCH] feat(*): Update readme with disposable stopwatch extensions --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d26c202..c3ab5bb 100644 --- a/README.md +++ b/README.md @@ -133,4 +133,28 @@ catch (Exception ex) List allInnerExceptionMessagesAndStackTraces = ex.AllInnerExceptionMessagesAndStackTraces(); ... } -``` \ No newline at end of file +``` + +## Logging Extensions + +### DisposableStopWatchExtension + +This extends `ILogger` with a timer that can wrap code with a using statement. It was heavily inspired by James Curran's [blog post](https://honestillusion.com/2021/12/14/Simple-timings.html). With this extension you can quickly, easily and cleanly stick `StopWatch` objects around code that you wish to time. + +```csharp +using (_logger.DisposableStopWatch()) +{ + ... +} +``` + +It takes in additional parameters for a message and whether or not to also write to a Console for quick and dirty iterating. + +```csharp +using (_logger.DisposableStopWatch("A message", true)) +{ + ... +} +``` + +You get a `Start:` log, with the message appended if you've passed it, and once your code within the using block has run you get `Complete:` with the messaged appended if you've passed it, then on the same line `Elapsed:` and the time elapsed in HH:MM:SS:MS..... format.