0
votes

In my ASP.NET Core application, I have configured the ILoggerFactory instance to output logs in Application Insights:

public class Startup
{
    ...

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(LogLevel.Debug);
        loggerFactory.AddDebug();

        // By default, set the minimum severity level to Information.      
        loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
        // ...
    }
}

Later, someClass is being injected the ILoggerFactory instance and it is logging a Debug message:

public class SomeClass
{
     private ILogger _logger;

     public SomeClass(ILoggerFactory loggerFactory)
     {
          _logger = loggerFactory.CreateLogger(nameof(SomeClass));
     }

     public void Do()
     {
          _logger.LogDebug($"Some debug message");
     }
}

Application Insights is configured separately from the ASP.NET Core app, not as an extension.

Since I have configured Application Insights to only log message with a severity higher than or equal to Informational message, I do not see the Debug traces.

Question

Is there a way to change the minimum logging level from the Azure Portal for troubleshooting purposes without having to recompile the application?

2

2 Answers

1
votes

Try modifying your appsettings.json - specifically add an ApplicationInsights section and adjust log level.

"Logging": {
    "IncludeScopes": false,
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "None"
      }
    },
    "LogLevel": {
      "Default": "Warning"
    }
  }

If your app did not have application insights, but installed application insights extension from Web Apps, then this should work.

Since you are already referring and setting log level in code, I am not 100% sure if this will work or not :(

0
votes

It is impossible since you have defined in your code: loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);

You could post the idea in the feedback.