-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
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