diff --git a/NucuCar.Domain.Telemetry/TelemetryWorker.cs b/NucuCar.Domain.Telemetry/TelemetryWorker.cs index 081da60..7f18ed0 100644 --- a/NucuCar.Domain.Telemetry/TelemetryWorker.cs +++ b/NucuCar.Domain.Telemetry/TelemetryWorker.cs @@ -51,6 +51,10 @@ namespace NucuCar.Telemetry await Task.Delay(_interval, stoppingToken); } } + catch (TaskCanceledException) + { + _logger?.LogInformation("The TelemetryWorker task was canceled."); + } catch (Exception e) { _logger?.LogError($"Unhandled exception in TelemetryWorker. {e.Message}"); diff --git a/NucuCar.Sensors/Program.cs b/NucuCar.Sensors/Program.cs index 6af3cc4..8ec70c7 100644 --- a/NucuCar.Sensors/Program.cs +++ b/NucuCar.Sensors/Program.cs @@ -31,9 +31,11 @@ namespace NucuCar.Sensors services.AddSingleton, Bme680Sensor>(); services.AddSingleton, CpuTempSensor>(); services.AddSingleton, HeartbeatSensor>(); - + // Workers + // Telemetry services.AddHostedService(); + // Sensors services.AddHostedService(); services.AddHostedService(); services.AddHostedService(); diff --git a/NucuCar.Sensors/SensorWorker.cs b/NucuCar.Sensors/SensorWorker.cs index 0fb393e..9700f58 100644 --- a/NucuCar.Sensors/SensorWorker.cs +++ b/NucuCar.Sensors/SensorWorker.cs @@ -67,9 +67,13 @@ namespace NucuCar.Sensors TelemetryPublisher?.UnRegisterTelemeter(Sensor); } + catch (TaskCanceledException) + { + Logger?.LogInformation("The SensorWorker task was canceled."); + } catch (Exception e) { - Logger?.LogError($"Unhandled exception in SensorWorker {sensorIdentifier}: {e.Message}"); + Logger?.LogError($"Unhandled exception in SensorWorker {sensorIdentifier}. {e.GetType()}: {e.Message}"); Logger?.LogDebug(e.StackTrace); } }