Fix logging behaviour in Pms5003Sensor.cs

This commit is contained in:
Denis-Cosmin Nutiu 2021-08-02 21:42:25 +03:00
parent e1ae7ecdd0
commit 4bdfb13e73
2 changed files with 8 additions and 5 deletions

View file

@ -11,6 +11,7 @@ namespace NucuCar.Sensors.Modules.PMS5003
{ {
public class Pms5003Sensor : GenericTelemeterSensor, IDisposable, ISensor<Pms5003Sensor> public class Pms5003Sensor : GenericTelemeterSensor, IDisposable, ISensor<Pms5003Sensor>
{ {
private readonly ILoggerFactory _loggerFactory;
private Pms5003 _pms5003; private Pms5003 _pms5003;
private Pms5003Data _pms5003Data; private Pms5003Data _pms5003Data;
@ -18,16 +19,17 @@ namespace NucuCar.Sensors.Modules.PMS5003
{ {
} }
public Pms5003Sensor(ILogger<Pms5003Sensor> logger, IOptions<Pms5003Config> options) public Pms5003Sensor(ILoggerFactory loggingFactory, IOptions<Pms5003Config> options)
{ {
CurrentState = SensorStateEnum.Uninitialized; CurrentState = SensorStateEnum.Uninitialized;
Logger = logger; Logger = loggingFactory.CreateLogger(nameof(Pms5003Sensor));
if (!options.Value.Enabled) if (!options.Value.Enabled)
{ {
Logger?.LogDebug("Pms5003 Sensor is disabled!"); Logger?.LogDebug("Pms5003 Sensor is disabled!");
CurrentState = SensorStateEnum.Disabled; CurrentState = SensorStateEnum.Disabled;
} }
_loggerFactory = loggingFactory;
TelemetryEnabled = options.Value.Telemetry; TelemetryEnabled = options.Value.Telemetry;
} }
@ -41,7 +43,7 @@ namespace NucuCar.Sensors.Modules.PMS5003
try try
{ {
Pms5003.Logger = (Logger<Pms5003>) Logger; Pms5003.Logger = new Logger<Pms5003>(_loggerFactory);
_pms5003 = new Pms5003(23, 24); _pms5003 = new Pms5003(23, 24);
_pms5003.Reset(); _pms5003.Reset();
CurrentState = SensorStateEnum.Initialized; CurrentState = SensorStateEnum.Initialized;

View file

@ -9,7 +9,8 @@ namespace NucuCar.Telemetry
{ {
public class TelemetryPublisherProxy : ITelemetryPublisher public class TelemetryPublisherProxy : ITelemetryPublisher
{ {
private ITelemetryPublisher Publisher { get; set; } // TODO: Add support for chaining publishers.
private ITelemetryPublisher Publisher { get; }
/// <summary> /// <summary>
/// Class used together with the DI, holds a Publisher instance that's being create by options from /// Class used together with the DI, holds a Publisher instance that's being create by options from