Skip to content

Configuration in applicationname.exe.nlog files do not load #3156

@ghost

Description

NLog version: 4.5.11
Platform: .NET Core 2
Current NLog config (xml or C#, if relevant)

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      throwExceptions="true" throwConfigExceptions="true">

  <targets>
    <target name="file" xsi:type="File"
            layout="${longdate} ${level} ${logger}: ${message} ${exception:format=ToString}"
            fileName="LogFiles/${shortdate}_LogFile.txt" keepFileOpen="true" encoding="utf-8"/>

    <target name="console" xsi:type="ColoredConsole"
            layout="${longdate} ${logger} ${level}: ${message} ${exception:format=ToString}"
            detectConsoleAvailable="true" />

  <rules>
    <logger name="*" minlevel="Debug" writeTo="file,console,viewer" />
  </rules>
</nlog>

According to https://github.com/nlog/nlog/wiki/Configuration-file it should be possible to have a configuration in a file called program.exe.nlog where program.exe is the executable for my program.

When the config file is in the applicationname.exe.nlog file, it does not work as expected.

Create a console application with the following Program.cs

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            foreach (var target in LogManager.Configuration.AllTargets)
                Console.WriteLine("Target: {0}", target.Name);
        }
    }

Publish the program with dotnet publish -c Release -r win-x64 and run the executable. The program crashes with Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object..

Rename the file to nlog.config and it works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement on existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions