From 2fadda9d9850be20eda84c37717c6138d39531b7 Mon Sep 17 00:00:00 2001 From: KatterMaw Date: Fri, 27 Oct 2023 10:26:20 +0500 Subject: [PATCH] Improve StreamDetector logging --- .../Prediction/StreamDetector.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/SightKeeper.Application/Prediction/StreamDetector.cs b/SightKeeper.Application/Prediction/StreamDetector.cs index ee82952e..d1b6f137 100644 --- a/SightKeeper.Application/Prediction/StreamDetector.cs +++ b/SightKeeper.Application/Prediction/StreamDetector.cs @@ -5,7 +5,7 @@ using CommunityToolkit.Diagnostics; using Serilog; using Serilog.Events; -using SerilogTimings; +using SerilogTimings.Extensions; using SightKeeper.Domain.Model; namespace SightKeeper.Application.Prediction; @@ -33,11 +33,13 @@ public bool IsEnabled { while (work) { - using var operation = Operation.At(LogEventLevel.Verbose).Begin("Detection cycle"); + using var operation = _logger.OperationAt(LogEventLevel.Debug).Begin("Detection cycle"); + using var screenCaptureOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Screen capture"); var image = await _screenCapture.CaptureAsync(); + screenCaptureOperation.Complete(nameof(image), image.Length); if (CheckImagesEquality) { - using var imagesComparisonOperation = Operation.Begin("Comparing images"); + using var imagesComparisonOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Comparing images"); var imagesAreEqual = image.SequenceEqual(previousImage); imagesComparisonOperation.Complete(nameof(imagesAreEqual), imagesAreEqual); if (imagesAreEqual) @@ -47,11 +49,12 @@ public bool IsEnabled } previousImage = image; } - + using var detectOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Detection"); var result = await _detector.Detect(image, CancellationToken.None); + detectOperation.Complete(nameof(result), result); if (IsEnabled) { - using var handlingOperation = Operation.Begin("Detection handling"); + using var handlingOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Detection handling"); observer.OnNext(new DetectionData(image, result.ToImmutableList())); handlingOperation.Complete(); } @@ -101,4 +104,5 @@ public StreamDetector(Detector detector, ScreenCapture screenCapture) private readonly ScreenCapture _screenCapture; private IDisposable? _isEnabledDisposable; private readonly Subject _detection = new(); + private readonly ILogger _logger = Log.ForContext(); } \ No newline at end of file