cnbucket
cnbucket

Reputation: 11

How to output Debug level log messages to Application Insights in production

A simple ASP.NET Core 2.0 web application, deployed in azure as an app service - edited to make sure the configurations are the same for ASPNETCORE_ENVIRONMENT development and production.

with the following in the Configure method of the Startup class:

loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Debug);

results in different behavior depending on the value of ASPNETCORE_ENVIRONMENT.

Using basic ASP.NET core logging, with Application insights configured I get the following behaviour:

With ASPNETCORE_ENVIRONMENT == development

LogDebug messages appear as trace messages in the Azure Portal Live Metrics Stream. However none of the applications messages seem to persist - they cant be queried through visual studio or analytics.applicationinsights.io

With ASPNETCORE_ENVIRONMENT == production

LogDebug messages DO NOT appear as trace messages in the Azure Portal Live Metrics Stream. The applications messages at level Information or above are persisted - they can be queried through visual studio or analytics.applicationinsights.io

Does anyone know how to get debug level messages to appear in the case ASPNETCORE_ENVIRONMENT == production ?

Maybe my google fu is weak, but I can't find any relevant documentation on this.

Upvotes: 1

Views: 5628

Answers (2)

Tim.Tang
Tim.Tang

Reputation: 3188

Add below code into your appsettings.json:

  "Logging": {
    "LogLevel": {
      "Default": "Debug"
    }
  },

Upvotes: 2

cijothomas
cijothomas

Reputation: 3126

ASPNETCORE_ENVIRONMENT variable does not control the logger behavior. Need some more info to understand why you are encountering this behavior. See this: https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/688

Upvotes: 0

Related Questions