From 5015ee920553f306ff2b8fd8d17545ffa7c03055 Mon Sep 17 00:00:00 2001 From: Mathew Charles Date: Thu, 11 Feb 2021 15:23:56 -0800 Subject: [PATCH] Fixing null ref in AI logger --- .../ApplicationInsightsLogger.cs | 10 ++++++- .../Loggers/ApplicationInsightsLoggerTests.cs | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs index 6aaf0596c..497309743 100644 --- a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs @@ -203,7 +203,15 @@ private void LogTrace(LogLevel logLevel, IEnumerable()); + foreach (var telemetry in _channel.Telemetries.Cast()) + { + Enum.TryParse(telemetry.Message, out LogLevel expectedLogLevel); + Assert.Equal(expectedLogLevel.ToString(), telemetry.Properties[LogConstants.LogLevelKey]); + Assert.Null(telemetry.SeverityLevel); + + Assert.Equal(5, telemetry.Properties.Count); + Assert.Equal(Process.GetCurrentProcess().Id.ToString(), telemetry.Properties[LogConstants.ProcessIdKey]); + Assert.Equal(_functionCategoryName, telemetry.Properties[LogConstants.CategoryNameKey]); + Assert.Equal(telemetry.Message, telemetry.Properties[LogConstants.CustomPropertyPrefix + LogConstants.OriginalFormatKey]); + Assert.Equal(scopeGuid.ToString(), telemetry.Properties[LogConstants.InvocationIdKey]); + Assert.Equal(telemetry.Message, telemetry.Properties[LogConstants.LogLevelKey]); + } + } + [Fact] public void DuplicateProperties_LastStateWins() {