Skip to content

Overriding appsettings.json with environment variable causes duplicated NLog output #320

@mbcrawfo

Description

@mbcrawfo

Type: Bug

NLog version: 4.6.7
NLog.Extensions.Logging version: 1.5.1
NLog.Web.AspNetCore version: 4.8.4

Platform: .NET Core 2.2

Current NLog config

{
  "NLog": {
    "extensions": {
      "NLog.Extensions.Logging": {
        "assembly": "NLog.Extensions.Logging"
      },
      "NLog.Web.AspNetCore": {
        "assembly": "NLog.Web.AspNetCore"
      }
    },
    "targets": {
      "console": {
        "type": "Console",
        "layout": "${level} | ${message}"
      }
    },
    "rules": {
      "console": {
        "logger": "*",
        "minLevel": "Trace",
        "writeTo": "console"
      }
    }
  }
}

I made a simple app based on the .Net Core API project template to reproduce the issue: https://github.com/mbcrawfo/nlog-dup

When you start the app, you'll notice that the messages written by NLog are duplicated four times:

image

If you modify launchSettings.json to remove the NLOG__RULES__CONSOLE__MINLEVEL environment variable, messages are only written once. Based on the internal config logging, it looks like the console rule is actually being processed four times:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions