Skip to content

Missing trace\debug logs in ASP.NET Core 6?

Rolf Kristensen edited this page Nov 8, 2022 · 8 revisions

Missing the trace and debug logs in ASP.NET Core 6?

Check your appsettings.json

The following is advised:

{
  "Logging": {
    "LogLevel": {
      "Default": "Trace",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

⚠️ Make sure also to check any environment specific appsettings.json. Ex. appsettings.development.json

Notice NLog.Web.AspNetCore ver. 5+ will by default ignore any filters configured in appsettings.json for Microsoft LoggerFactory. Instead it will only react to the logging-rules in NLog.config. The options ReplaceLoggerFactory and RemoveLoggerFactoryFilter in NLogAspNetCoreOptions can be used to re-enable the old behavior. Example:

.UseNLog(new NLogAspNetCoreOptions() { RemoveLoggerFactoryFilter = false });

The recommended solution is updating the NLog configuration to include the wanted filtering:

<rules>
    <logger name="System.*" finalMinLevel="Warn" />    <!-- Insert at the top -->
    <logger name="Microsoft.*" finalMinLevel="Warn" /> <!-- Insert at the top -->

    <!-- Everything else -->
</rules>

See also: https://nlog-project.org/2021/08/25/nlog-5-0-preview1-ready.html#nlogextensionslogging-without-any-filter