diff --git a/Creek.HelpfulExtensions/Creek.HelpfulExtensions.csproj b/Creek.HelpfulExtensions/Creek.HelpfulExtensions.csproj
index 5a466f2..a003d43 100644
--- a/Creek.HelpfulExtensions/Creek.HelpfulExtensions.csproj
+++ b/Creek.HelpfulExtensions/Creek.HelpfulExtensions.csproj
@@ -19,8 +19,8 @@
LICENSE
git
creek
- 1.4.1
- 1.4.0.1
+ 1.4.3
+ 1.4.0.3
diff --git a/Creek.HelpfulExtensions/DisposableStopWatchExtension.cs b/Creek.HelpfulExtensions/DisposableStopWatchExtension.cs
index 41df996..09ba85f 100644
--- a/Creek.HelpfulExtensions/DisposableStopWatchExtension.cs
+++ b/Creek.HelpfulExtensions/DisposableStopWatchExtension.cs
@@ -6,14 +6,16 @@ namespace Creek.HelpfulExtensions
{
public class DisposableStopWatch : IDisposable
{
- private ILogger _logger;
+ private readonly ILogger _logger;
private Stopwatch _stopWatch;
private string _message;
private bool _useConsole;
+ private bool _useConsoleOnly;
public DisposableStopWatch(ILogger logger, string message = null, bool useConsole = false)
{
_logger = logger;
+ _useConsoleOnly = false;
_stopWatch = new Stopwatch();
_message = message ?? string.Empty;
_useConsole = useConsole;
@@ -33,13 +35,30 @@ namespace Creek.HelpfulExtensions
_stopWatch.Start();
}
+ public DisposableStopWatch(string message = null)
+ {
+ _useConsoleOnly = true;
+ _stopWatch = new Stopwatch();
+ _message = message ?? string.Empty;
+
+ string startMessage = $"Start: {message}";
+
+ Console.WriteLine(startMessage);
+
+ _stopWatch.Start();
+ }
+
public void Dispose()
{
_stopWatch.Stop();
string endMessage = $"Complete:{_message}: Elapsed: {_stopWatch.Elapsed}";
- if (_useConsole)
+ if (_useConsoleOnly)
+ {
+ Console.WriteLine(endMessage);
+ }
+ else if (_useConsole)
{
_logger.LogInformation(endMessage);
Console.WriteLine(endMessage);
@@ -54,5 +73,7 @@ namespace Creek.HelpfulExtensions
public static class DisposableStopWatchExtension
{
public static DisposableStopWatch DisposableStopWatch(this ILogger logger, string message = null, bool useConsole = false) => new DisposableStopWatch(logger, message, useConsole);
+
+ public static DisposableStopWatch DisposableStopWatch(this string message) => new DisposableStopWatch(message);
}
}
diff --git a/README.md b/README.md
index c3ab5bb..323ff94 100644
--- a/README.md
+++ b/README.md
@@ -157,4 +157,13 @@ using (_logger.DisposableStopWatch("A message", true))
}
```
+You can also make use of it without a logger for very barebones console applications.
+
+```csharp
+using ("A message".DisposableStopWatch())
+{
+ ...
+}
+```
+
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.