diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/LogsHelper.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/LogsHelper.cs index 99c4a33089222..199868ecbcf0f 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/LogsHelper.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/LogsHelper.cs @@ -52,13 +52,7 @@ internal static List OtelToAzureMonitorLogs(Batch batc internal static string GetMessageAndSetProperties(LogRecord logRecord, IDictionary properties) { - string message = null; - var isFormattedMessage = logRecord.FormattedMessage != null; - - if (isFormattedMessage) - { - message = logRecord.FormattedMessage; - } + string message = logRecord.FormattedMessage; // Both logRecord.State and logRecord.StateValues will not be set at the same time for LogRecord. // Either logRecord.State != null or logRecord.StateValues will be called. @@ -66,13 +60,13 @@ internal static string GetMessageAndSetProperties(LogRecord logRecord, IDictiona { if (logRecord.State is IReadOnlyCollection> stateDictionary) { - ExtractProperties(ref message, properties, stateDictionary, isFormattedMessage); + ExtractProperties(ref message, properties, stateDictionary); } } if (logRecord.StateValues != null) { - ExtractProperties(ref message, properties, logRecord.StateValues, isFormattedMessage); + ExtractProperties(ref message, properties, logRecord.StateValues); } if (logRecord.EventId.Id != 0) @@ -143,13 +137,13 @@ internal static SeverityLevel GetSeverityLevel(LogLevel logLevel) } } - private static void ExtractProperties(ref string message, IDictionary properties, IReadOnlyCollection> stateDictionary, bool isFormattedMessage) + private static void ExtractProperties(ref string message, IDictionary properties, IReadOnlyCollection> stateDictionary) { foreach (KeyValuePair item in stateDictionary) { if (item.Key == "{OriginalFormat}") { - if (!isFormattedMessage) + if (message == null) { message = item.Value.ToString(); }