示例#1
0
        public override bool HandleException(Exception ex, ITelemetryLogger logger)
        {
            EnsureArg.IsNotNull(ex, nameof(ex));
            EnsureArg.IsNotNull(logger, nameof(logger));

            var exceptionTypeName = ex.GetType().Name;

            return(HandleException(ex, logger, IomtMetrics.HandledException(exceptionTypeName, _connectorStage), IomtMetrics.UnhandledException(exceptionTypeName, _connectorStage)));
        }
示例#2
0
        public virtual bool HandleException(Exception ex, ITelemetryLogger log, string connectorStage)
        {
            EnsureArg.IsNotNull(ex, nameof(ex));
            EnsureArg.IsNotNull(log, nameof(log));

            var exType = ex.GetType();

            var lookupType = exType.IsGenericType ? exType.GetGenericTypeDefinition() : exType;

            if (_handledExceptions.Contains(lookupType))
            {
                if (ex is ITelemetryFormattable tel)
                {
                    log.LogMetric(
                        metric: tel.ToMetric,
                        metricValue: 1);
                }
                else
                {
                    if (ex is NotSupportedException)
                    {
                        var metric = IomtMetrics.NotSupported();
                        log.LogMetric(
                            metric: metric,
                            metricValue: 1);
                    }
                    else
                    {
                        var metric = IomtMetrics.HandledException(
                            exType.Name,
                            connectorStage);
                        log.LogMetric(
                            metric: metric,
                            metricValue: 1);
                    }
                }

                return(true);
            }

            return(false);
        }