diff --git a/src/WebJobs.Script.WebHost/Diagnostics/LinuxAppServiceEventGenerator.cs b/src/WebJobs.Script.WebHost/Diagnostics/LinuxAppServiceEventGenerator.cs index 03d2e80e7f..42bc70ce2e 100644 --- a/src/WebJobs.Script.WebHost/Diagnostics/LinuxAppServiceEventGenerator.cs +++ b/src/WebJobs.Script.WebHost/Diagnostics/LinuxAppServiceEventGenerator.cs @@ -110,7 +110,8 @@ private void WriteEvent(string eventPayload) public override void LogAzureMonitorDiagnosticLogEvent(LogLevel level, string resourceId, string operationName, string category, string regionName, string properties) { - _writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{NormalizeString(properties.Replace("'", string.Empty))},{DateTime.UtcNow}"); + var timeStr = IsAzureMonitorTimeIsoFormatEnabled() ? DateTime.UtcNow.ToString("s") : DateTime.UtcNow.ToString(); + _writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{NormalizeString(properties.Replace("'", string.Empty))},{timeStr}"); } public static void LogUnhandledException(Exception e) @@ -118,5 +119,19 @@ public static void LogUnhandledException(Exception e) // Pipe the unhandled exception to stdout as part of docker logs. Console.WriteLine($"Unhandled exception on {DateTime.UtcNow}: {e?.ToString()}"); } + + private bool IsAzureMonitorTimeIsoFormatEnabled() + { + string enabledString = Environment.GetEnvironmentVariable(EnvironmentSettingNames.AzureMonitorTimeIsoFormatEnabled); + if (bool.TryParse(enabledString, out bool result)) + { + return result; + } + if (int.TryParse(enabledString, out int enabledInt)) + { + return Convert.ToBoolean(enabledInt); + } + return false; + } } } diff --git a/src/WebJobs.Script/Environment/EnvironmentSettingNames.cs b/src/WebJobs.Script/Environment/EnvironmentSettingNames.cs index 4108e1a673..e7d3a70a59 100644 --- a/src/WebJobs.Script/Environment/EnvironmentSettingNames.cs +++ b/src/WebJobs.Script/Environment/EnvironmentSettingNames.cs @@ -71,6 +71,7 @@ public static class EnvironmentSettingNames public const string HealthPingEnabled = "WEBSITE_FUNCTIONS_HEALTH_PING_ENABLED"; public const string TestDataCapEnabled = "WEBSITE_FUNCTIONS_TESTDATA_CAP_ENABLED"; public const string AzureMonitorCategories = "WEBSITE_FUNCTIONS_AZUREMONITOR_CATEGORIES"; + public const string AzureMonitorTimeIsoFormatEnabled = "FUNCTIONS_AZUREMONITOR_TIME_ISOFORMAT_ENABLED"; public const string FunctionsRequestBodySizeLimit = "FUNCTIONS_REQUEST_BODY_SIZE_LIMIT"; public const string FunctionsHostIdCheckLevel = "FUNCTIONS_HOSTID_CHECK_LEVEL"; public const string FunctionsPlatformConfigFilePath = "FUNCTIONS_PLATFORM_CONFIG_FILE_PATH";