NucuCar.Domain: Fix TelemtryPublisherDisk not publishing messages

This commit is contained in:
Denis-Cosmin Nutiu 2020-01-24 15:55:40 +02:00
parent 3b7f67fcfe
commit aad410f3ac

View file

@ -16,7 +16,6 @@ namespace NucuCar.Domain.Telemetry
public class TelemetryPublisherDisk : TelemetryPublisher
{
private readonly FileStream _fileStream;
private int _charactersWritten;
/// <summary>
/// Constructs an instance of <see cref="TelemetryPublisherDisk"/>.
@ -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()