If I log an exception with some key/value pairs added to Data, those values do not get logged. They would be really helpful for diagnosis of the issue in some cases but I can't see any way to configure that.
For example, the following console app:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.2" />
</ItemGroup>
</Project>
class Program
{
static void Main(string[] args)
{
var exception = new Exception("Oops!");
exception.Data.Add("useful-data-key", "useful-data-value");
ILogger<Program> logger = LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger<Program>();
logger.LogError(exception, "An error occurred in the console.");
Console.WriteLine("Logged");
Console.Read();
}
}
Results in this being logged to the console:
fail: Console.Program[0]
An error occurred in the console.
System.Exception: Oops!
No sign of the values in the Data dictionary.
The same is true if I log to Azure Application Insight in an ASP.NET Core app.
Is there any way I can get that data to output in the logs?