Skip to content

[BUG] UseAzureMonitor does not appear to support Structured Logging for messages. #45691

@Bpflugrad

Description

@Bpflugrad

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore 1.2.0

Describe the bug

When using ILogger for logging with UseAzureMonitor as the OpenTelemetry exporter, Structured Logging is not being performed.

Message arguments are logged as Custom Properties in Application Insights, but the "OriginalFormat" property is not present. The "Message" property contains the interpolated string.

The "OriginalFormat" property is logged for Exceptions, but not messages.

Expected behavior

Traces in Application Insights should include the "OriginalFormat" property, to allow aggregating log messages by their pre-formatted values.

Actual behavior

"OriginalFormat" is not present on (Application Insights) Traces, and is only present for Exceptions.

Reproduction Steps

I've created a minimal example project showing the behaviors.

Example controller:

using Microsoft.AspNetCore.Mvc;

namespace AspireLoggingExample.Api.Controllers;

[ApiController]
[Route("[controller]")]
public class AttributeLogController(ILogger<AttributeLogController> logger) : ControllerBase
{
    [HttpGet(Name = "GetAttributeLog")]

    public string Get()
    {
        const string logMessage = "LogFromAttributeMessage({value})";

        logger.LogFromAttributeMessage(9001);

        return logMessage;
    }
}

internal static partial class LoggerExtensions
{
    [LoggerMessage(LogLevel.Information, "LogFromAttributeMessage({value})")]
    internal static partial void LogFromAttributeMessage(this ILogger logger, int value);
}

Environment

Aspire version: 8.0.1+a6e341ebbf956bbcec0dda304109815fcbae70c9
Microsoft Visual Studio Enterprise 2022 (64-bit): 17.10.3

Metadata

Metadata

Assignees

Labels

ClientThis issue is related to a non-management packageMonitorMonitor, Monitor Ingestion, Monitor Querycustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions