in src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs [109:168]
private void LogMetric(IEnumerable<KeyValuePair<string, object>> values, LogLevel logLevel, EventId eventId)
{
MetricTelemetry telemetry = new MetricTelemetry();
// Always apply scope first to allow state to override.
ApplyScopeProperties(telemetry);
// Do not apply state properties if optimization is enabled
if (!_loggerOptions.EnableMetricsCustomDimensionOptimization)
{
// Add known properties like category, logLevel and event
ApplyKnownProperties(telemetry.Properties, logLevel, eventId);
}
foreach (var entry in values)
{
if (entry.Value == null)
{
continue;
}
// Name and Value are not lower-case so check for them explicitly first and move to the
// next entry if found.
switch (entry.Key)
{
case LogConstants.NameKey when entry.Value is string name:
telemetry.Name = name;
continue;
case LogConstants.MetricValueKey when entry.Value is double sum:
telemetry.Sum = sum;
continue;
case LogConstants.OriginalFormatKey:
continue;
default:
break;
}
// Now check for case-insensitive matches
switch (entry.Key.ToLowerInvariant())
{
case MetricCountKey when entry.Value is int count:
telemetry.Count = count;
break;
case MetricMinKey:
telemetry.Min = Convert.ToDouble(entry.Value);
break;
case MetricMaxKey:
telemetry.Max = Convert.ToDouble(entry.Value);
break;
case MetricStandardDeviationKey:
telemetry.StandardDeviation = Convert.ToDouble(entry.Value);
break;
default:
// Otherwise, it's a custom property.
ApplyProperty(telemetry, entry, true);
break;
}
}
_telemetryClient.TrackMetric(telemetry);
}