using Infineon.Monitoring.MonA; namespace FabApprovalWorkerService.Services; public interface IMonInClient { void PostMetric(string metricName, double metricValue); void PostStatus(string statusName, State state); } public class MonInClient : IMonInClient { private readonly ILogger _logger; private readonly string _site; private readonly string _resource; public MonInClient(ILogger logger) { _logger = logger ?? throw new ArgumentNullException("ILogger not injected"); _site = Environment.GetEnvironmentVariable("MonInSite") ?? throw new ArgumentNullException("MonInSite environment variable not found"); _resource = Environment.GetEnvironmentVariable("FabApprovalWorkerServiceMonInResource") ?? throw new ArgumentNullException("FabApprovalWorkerServiceMonInResource environment variable not found"); } public void PostMetric(string metricName, double metricValue) { try { _logger.LogInformation("Attempting to send MonIn metric request for resource {0} with name {1} and value {2}", _resource, metricName, metricValue); MonIn.GetInstance().SendPerformanceMessage(_site, _resource, metricName, metricValue); } catch (Exception ex) { _logger.LogError("An exception occurred when attempting to send MonIn metric request for resource {0} with name {1} and value {2}. Exception: {3}", _resource, metricName, metricValue, ex.Message); } } public void PostStatus(string statusName, State state) { try { _logger.LogInformation("Attempting to send MonIn status request for resource {0} with name {1} and value {2}", _resource, statusName, state.ToString()); MonIn.GetInstance().SendStatus(_site, _resource, statusName, state); } catch (Exception ex) { _logger.LogError("An exception occurred when attempting to send MonIn status request for resource {0} with name {1} and value {2}. Exception: {3}", _resource, statusName, state.ToString(), ex.Message); } } }