Visitar URL original
Issues with logging in WorkerService project after upgrading to v6.0.1 · Issue #5928 · NLog/NLog · GitHub
Skip to content

Issues with logging in WorkerService project after upgrading to v6.0.1 #5928

Closed

Description

@elfico

Hi! Thanks for reporting this bug!

NLog version: 6.0.1

Platform: .NET9 (Worker Service)

Current NLog config (xml or C#, if relevant)

<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogFile=".\logs\internal.log"
	  internalLogToConsole="true"
	  throwConfigExceptions="true"
      internalLogLevel="Info">

	<!-- the targets to write to -->
	<targets>
		<!-- write logs to file -->
		<target xsi:type="File" name="fileLog" fileName=".\logs\nlog-all-${shortdate}.log"
				layout="${date}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}" />
	</targets>

	<!-- rules to map from logger name to target -->
	<rules>
		<logger name="*" minlevel="Info" writeTo="fileLog" />
		<logger name="*" minlevel="Error" writeTo="fileLog" />
		<!--<logger name="*" minlevel="Error" writeTo="fileLog, mailLog" />-->
	</rules>

</nlog>

<!--link https://github.com/nlog/NLog/wiki/Mail-target-->
  • What is the current result?
    There is no output for both the internal log and the application log.

  • What is the expected result?
    There should be at least 1 log file.

  • Did you check the Internal log?
    Yes, I did. Added some configuration, but nothing yet

  • Please post full exception details (message, stacktrace, inner exceptions)
    Attached is the screenshot showing what the logger looks like when inspected.

  • Are there any workarounds? yes/no
    No workaround that I know of.

  • Is there a version in which it did work?
    Downgrading to version 5.4.0 solves the issue

  • Can you help us by writing a unit test?
    Yes, I can.

I have also developed a minimal reproducible version here: https://github.com/elfico/nlog-test

Activity

  1. welcome commented on Jul 14, 2025

    @welcome

    Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

  2. changed the title [-]Issues with logging in WorkerService project after upgrading to v6.0.0[/-] [+]Issues with logging in WorkerService project after upgrading to v6.0.1[/+] on Jul 14, 2025
  3. snakefoot commented on Jul 15, 2025

    @snakefoot
    Contributor

    Yes the new NLog XmlParser introduced with NLog v6, needs some more tender-loving-and-care. I have now created the following improvements:

    As a work-around until NLog v6.0.2. then I recommend removing this from your NLog.config-file after the </nlog>-end-tag:

    <!--link https://github.com/nlog/NLog/wiki/Mail-target-->

    Thank you again for this feedback, and helping with improving the NLog-logging-library.

  4. added this to the 6.0.2 milestone on Jul 15, 2025
  5. elfico commented on Jul 15, 2025

    @elfico
    Author

    Thanks!
    It's working now!

  6. snakefoot commented on Jul 15, 2025

    @snakefoot
    Contributor

    Happy to hear, soon NLog v6.0.2 will be out, so others will not be blocked by the same issue.

  7. snakefoot commented on Jul 20, 2025

    @snakefoot
    Contributor

    NLog v6.0.2 has been released:

    Thank you again for the feedback

  8. elfico commented on Oct 21, 2025

    @elfico
    Author

    Hi @snakefoot

    I am experiencing similar issue when I updated to the latest NLog v6.0.5

    Here is my configuration:

    <?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"
          autoReload="true"
          internalLogFile=".\logs\internal.log"
          internalLogLevel="Info"
    	  throwConfigExceptions="true"
    	  internalLogToConsole="true">
    
      <targets>
        <target xsi:type="File" name="fileLog" fileName=".\logs\nlog-all-${shortdate}.log"
                layout="${date}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}" />    
      </targets>
    
      <rules>
        <logger name="*" minlevel="Error" writeTo="fileLog" />
      </rules>
    </nlog>
    

    And content of my internal.log

    2025-10-21 14:44:46.2293 Info Registered target NLog.Targets.FileTarget(Name=fileLog)
    2025-10-21 14:44:46.2872 Info NLog, Version=6.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 6.0.5.4631. Product version: 6.0.5+a023270f66a9445456a70c06668acabe7179c723. GlobalAssemblyCache: False
    2025-10-21 14:44:46.4057 Info Configuration initialized: TargetNames=fileLog, ConfigItems=18, AutoReload=true, FilePath=C:\Users\User1\source\repos\projects\Uploader\bin\Debug\net9.0\NLog.config
    2025-10-21 14:44:58.6190 Info LogFactory shutting down ...
    2025-10-21 14:44:58.6190 Info Closing old configuration.
    2025-10-21 14:44:58.6276 Info LogFactory shutdown completed.
    2025-10-21 14:44:58.6276 Info AppDomain Shutting down. LogFactory closing...
    2025-10-21 14:44:58.6378 Info LogFactory has been disposed.
    
    
  9. reopened this on Oct 21, 2025
  10. snakefoot commented on Oct 21, 2025

    @snakefoot
    Contributor

    Please don't awaken/reopen old closed issues for reporting new issues, instead open a new issue.

    P.S. From you looking at the NLog InternalLogger-output then there are no errors, so I'm guessing the issue is <logger name="*" minlevel="Error" writeTo="fileLog" /> and your application is not logging any errors (minlevel="Error"). Remember to check NLog Troubleshooting Guide before reporting issues.

    This is the output from NLog InternalLogger when using your NLog.config in an example app that generates Error-output (File is successfully created and has the expected output):

    2025-10-21 18:19:42.8996 Debug Message Template Auto Format enabled
    2025-10-21 18:19:42.9233 Debug Adding target NLog.Targets.FileTarget(Name=fileLog)
    2025-10-21 18:19:42.9233 Info Registered target NLog.Targets.FileTarget(Name=fileLog)
    2025-10-21 18:19:42.9233 Info NLog, Version=6.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 6.0.5.4631. Product version: 6.0.5+a023270f66a9445456a70c06668acabe7179c723. GlobalAssemblyCache: False
    2025-10-21 18:19:42.9233 Debug AutoReload Config File Monitor refreshing after configuration changed
    2025-10-21 18:19:42.9233 Debug AutoReload Config File Monitor starting
    2025-10-21 18:19:42.9233 Debug Start watching file-filter 'NLog.config' in directory: D:\Repos\NLog.Extensions.Logging\Examples\NetCore2\ConsoleExample\bin\Debug\net8.0
    2025-10-21 18:19:42.9233 Debug --- NLog configuration dump ---
    2025-10-21 18:19:42.9233 Debug Targets:
    2025-10-21 18:19:42.9233 Debug FileTarget(Name=fileLog)
    2025-10-21 18:19:42.9233 Debug Rules:
    2025-10-21 18:19:42.9233 Debug logNamePattern: (:All) levels: [ Error Fatal ] writeTo: [ fileLog ]
    2025-10-21 18:19:42.9233 Debug --- End of NLog configuration dump ---
    2025-10-21 18:19:42.9233 Debug Unused target checking is started... Rule Count: 1, Target Count: 1
    2025-10-21 18:19:42.9387 Debug Unused target checking is completed. Total Rule Count: 1, Total Target Count: 1, Unused Target Count: 0
    2025-10-21 18:19:42.9387 Info Configuration initialized: TargetNames=fileLog, ConfigItems=18, AutoReload=true, FilePath=D:\Repos\NLog.Extensions.Logging\Examples\NetCore2\ConsoleExample\bin\Debug\net8.0\NLog.config
    2025-10-21 18:19:42.9387 Debug Targets configured when LogLevel >= Error for Logger: ConsoleExample.Runner
    2025-10-21 18:19:42.9387 Debug Logger ConsoleExample.Runner [Error] => fileLog
    2025-10-21 18:19:42.9387 Debug Logger ConsoleExample.Runner [Fatal] => fileLog
    2025-10-21 18:19:42.9582 Debug FileTarget(Name=fileLog): Verify directory and creating writer to file: D:\Repos\NLog.Extensions.Logging\Examples\NetCore2\ConsoleExample\bin\Debug\net8.0\logs\nlog-all-2025-10-21.log
    
  11. elfico commented on Oct 21, 2025

    @elfico
    Author

    Please don't awaken/reopen old closed issues for reporting new issues, instead open a new issue.

    P.S. From you looking at the NLog InternalLogger-output then there are no errors, so I'm guessing the issue is <logger name="*" minlevel="Error" writeTo="fileLog" /> and your application is not logging any errors (minlevel="Error"). Remember to check NLog Troubleshooting Guide before reporting issues.

    Thanks for the quick response.
    Sorry about that. Will create a new issue going forward.

    I followed the troubleshooting guide, but could not resolve the issue. The application is logging errors. Plus, it is working with v6.0.2 and only stopped when I updated the NuGet.
    So, same code and config, but different updated NuGet packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug report / Bug fix

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions