From aad410f3ac93ef74d0337231c4f1f851fee13e64 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin Nutiu Date: Fri, 24 Jan 2020 15:55:40 +0200 Subject: [PATCH] NucuCar.Domain: Fix TelemtryPublisherDisk not publishing messages --- .../Telemetry/TelemetryPublisherDisk.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/NucuCar.Domain/Telemetry/TelemetryPublisherDisk.cs b/NucuCar.Domain/Telemetry/TelemetryPublisherDisk.cs index 72ce43f..049a17a 100644 --- a/NucuCar.Domain/Telemetry/TelemetryPublisherDisk.cs +++ b/NucuCar.Domain/Telemetry/TelemetryPublisherDisk.cs @@ -16,7 +16,6 @@ namespace NucuCar.Domain.Telemetry public class TelemetryPublisherDisk : TelemetryPublisher { private readonly FileStream _fileStream; - private int _charactersWritten; /// /// Constructs an instance of . @@ -47,10 +46,17 @@ namespace NucuCar.Domain.Telemetry Logger?.LogDebug($"Telemetry message: {messageString}"); var encodedText = Encoding.Unicode.GetBytes(messageString); - await _fileStream.WriteAsync(encodedText, _charactersWritten, - encodedText.Length, cancellationToken); - _charactersWritten += encodedText.Length; - await _fileStream.FlushAsync(cancellationToken); + try + { + await _fileStream.WriteAsync(encodedText, 0, + encodedText.Length, cancellationToken); + await _fileStream.FlushAsync(cancellationToken); + } + catch (ObjectDisposedException e) + { + Logger.LogCritical(e.Message); + } + } public override void Dispose()