Search code examples
loggingasp.net-coreasp.net-core-2.0azure-application-insights

How can I get Logger.BeginScope to work with Application Insights?


I've read somewhere that Application Insights should work with structured logs, and I'm trying to log data to Application Insights using ILogger's BeginScope:

using (_logger.BeginScope("Some really useful information"))
{
    // something something

    _logger.LogError("Oh no.");
}

However, when inspecting the trace in Application Insights, I'm not getting the log data from BeginScope, just "Oh no" in this case. This is a .NET Core 2.0 application. Is BeginScope not supported with the default implementation of Application Insights ILogger? Or am I missing something?


Solution

  • I fixed this problem by using Serilog with it's Application Insights sink. Worked perfectly.