diff --git a/src/lib/Microsoft.Health.Logger/Telemetry/IomtTelemetryLogger.cs b/src/lib/Microsoft.Health.Logger/Telemetry/IomtTelemetryLogger.cs index 5647c75a..550f763a 100644 --- a/src/lib/Microsoft.Health.Logger/Telemetry/IomtTelemetryLogger.cs +++ b/src/lib/Microsoft.Health.Logger/Telemetry/IomtTelemetryLogger.cs @@ -28,7 +28,15 @@ public virtual void LogMetric(Common.Telemetry.Metric metric, double metricValue public virtual void LogError(Exception ex) { - _telemetryClient.TrackException(ex); + if (ex is AggregateException e) + { + // Address bug https://github.com/microsoft/iomt-fhir/pull/120 + LogAggregateException(e); + } + else + { + _telemetryClient.TrackException(ex); + } } public virtual void LogTrace(string message) @@ -41,5 +49,18 @@ public void LogMetricWithDimensions(Common.Telemetry.Metric metric, double metri EnsureArg.IsNotNull(metric); metric.LogMetric(_telemetryClient, metricValue); } + + private void LogAggregateException(AggregateException e) + { + if (e.InnerException != null) + { + _telemetryClient.TrackException(e.InnerException); + } + + foreach (var exception in e.InnerExceptions) + { + _telemetryClient.TrackException(exception); + } + } } }