Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nlog 5.3.8 no longer loads NLog.config, if it's a linked file. #1059

Closed
erikbozic opened this issue Sep 23, 2024 · 6 comments
Closed

Nlog 5.3.8 no longer loads NLog.config, if it's a linked file. #1059

erikbozic opened this issue Sep 23, 2024 · 6 comments
Labels

Comments

@erikbozic
Copy link

NLog version: > 5.3.8

Platform: .NET8

Current NLog config

<?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"
			internalLogLevel="info"
			internalLogToConsole="true">

	<variable name="LogDir" value="${basedir}/logs/"/>
	<variable name="ApplicationName" value="${appdomain:format={1\}}"/>

	<!-- Enable ASP.NET Core layout renderers -->
	<extensions>
		<add assembly="NLog.Web.AspNetCore"/>
		<add assembly="NLog.DiagnosticSource"/>
	</extensions>

	<targets async="true">
		<!-- Files -->
		<target xsi:type="File" name="applicationFile" fileName="${LogDir}${ApplicationName}-application-${shortdate}.log"
						layout="${longdate} ${level:uppercase=true:padding=-5} ${activity:property=TraceId} [${activity:property=Baggage:item=OperationName}] ${activity:property=Baggage:item=InstanceId} ${logger}: ${message} ${exception:format=tostring:trimWhiteSpace=true}"/>
		<target xsi:type="File" name="webHost" fileName="${LogDir}${ApplicationName}-webhost-${shortdate}.log"
						layout="${longdate:universalTime=true}|${event-properties:item=EventId_Id}|${threadid}|${uppercase:${level}}|${message} ${exception:format=tostring}"/>
		<target xsi:type="File" name="auditLogFile" fileName="${LogDir}${ApplicationName}-audit-${shortdate}.log"
						layout="${longdate} ${level:uppercase=true:padding=-5} ${logger}:${activity:property=TraceId} ${message} ${exception:format=tostring:trimWhiteSpace=true}"/>
		<!-- Console target -->
		<target xsi:type="ColoredConsole" name="console"
						layout="${date:format=HH\:mm\:ss} ${level:uppercase=true:padding=-5} ${logger}:${activity:property=TraceId} ${message} ${exception:format=tostring:trimWhiteSpace=true}"/>
	</targets>

	<rules>
		<!-- Any logger postfixed with 'AuditLogger' is used for audit logs. -->
		<logger name="*AuditLogger" writeTo="console,auditLogFile" final="true"/>
		<!--All logs, including from Microsoft -->
		<logger name="Microsoft.AspNetCore.Hosting.*" minLevel="Info" writeTo="console,webHost" final="true"/>
		<!--Skip non-critical Microsoft logs and so log only own logs -->
		<logger name="Microsoft.*" maxLevel="Warn" final="true"/>
		<!-- Log the rest -->
		<logger name="*" writeTo="applicationFile,console"/>
	</rules>

</nlog>

There are no logs, if I link the NLog.config file from another project like this:

  <ItemGroup>
    <None Include="..\..\Shared\Infrastructure\NLog.config" Link="NLog.config"/>
  </ItemGroup>

It seems to behave the same as the already reported bug here: NLog/NLog#5045
If I add this it starts working: LogManager.Setup().LoadConfigurationFromFile().

This only happens with version 5.3.8 or higher, it still works on 5.3.7. I'm running this on Linux.

I've also enabled the internal logger.
With 5.3.7 I get:

2024-09-23 19:20:36.4222 Debug Hide assemblies for callsite
2024-09-23 19:20:36.4631 Debug Skip loading NLogLoggingConfiguration from empty config section: NLog
2024-09-23 19:20:36.4675 Debug No file exists at candidate config file location: /home/erik/src/project_path/App/bin/Debug/net8.0/Project.App.exe.nlog
2024-09-23 19:20:36.4675 Debug No file exists at candidate config file location: /home/erik/src/project_path/App/bin/Debug/net8.0/Project.App.dll.nlog
2024-09-23 19:20:36.4675 Debug No file exists at candidate config file location: /home/erik/src/project_path/App/bin/Debug/net8.0/NLog.config
2024-09-23 19:20:36.4759 Debug Reading config from XML file: /home/erik/src/project_path/App/bin/Debug/net8.0/nlog.config
2024-09-23 19:20:36.4829 Info Loading NLog config from XML file: /home/erik/src/project_path/App/bin/Debug/net8.0/nlog.config
2024-09-23 19:20:36.4996 Info Loading assembly name: NLog.DiagnosticSource
2024-09-23 19:20:36.5080 Info NLog.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.1.363. Product version: 5.2.1+a54f7fe24a23b4dc9ee731cf22586ac0ca2d167b. GlobalAssemblyCache: False
2024-09-23 19:20:36.5553 Info Registered target NLog.Targets.Wrappers.AsyncTargetWrapper(Name=applicationFile)
2024-09-23 19:20:36.5574 Info Registered target NLog.Targets.Wrappers.AsyncTargetWrapper(Name=webHost)
2024-09-23 19:20:36.5574 Info Registered target NLog.Targets.Wrappers.AsyncTargetWrapper(Name=auditLogFile)
2024-09-23 19:20:36.5685 Info Registered target NLog.Targets.Wrappers.AsyncTargetWrapper(Name=console)
2024-09-23 19:20:36.5773 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.7.2287. Product version: 5.2.7+a1ef7cd83b5a6a172142a6850f0ced4e759a4b3b. GlobalAssemblyCache: False
2024-09-23 19:20:36.5919 Info Validating config: TargetNames=console, auditLogFile, webHost, applicationFile, ConfigItems=90, FilePath=/home/erik/src/project_path/App/bin/Debug/net8.0/nlog.config
2024-09-23 19:20:36.6116 Info Configuration initialized.
2024-09-23 19:20:36.6116 Info Validating config: TargetNames=console, auditLogFile, webHost, applicationFile, ConfigItems=90, FilePath=/home/erik/src/project_path/App/bin/Debug/net8.0/nlog.config

After which it starts logging application logs.

However with 5.3.8 I get:

/home/erik/src/project_path/App/bin/Debug/net8.0/Project.App
2024-09-23 19:21:37.3146 Debug Hide assemblies for callsite
2024-09-23 19:21:37.4128 Debug Skip loading NLogLoggingConfiguration from empty config section: NLog
2024-09-23 19:21:37.4298 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-09-23 19:21:37.4298 Debug --- NLog configuration dump ---
2024-09-23 19:21:37.4298 Debug Targets:
2024-09-23 19:21:37.4298 Debug Rules:
2024-09-23 19:21:37.4298 Debug --- End of NLog configuration dump ---
2024-09-23 19:21:37.4370 Info Validating config: Targets=0, ConfigItems=0
2024-09-23 19:21:37.4404 Info Configuration initialized.
2024-09-23 19:21:37.4661 Debug Targets not configured for Logger: Microsoft.Extensions.Hosting.Internal.ApplicationLifetime
2024-09-23 19:21:37.4723 Debug Targets not configured for Logger: Microsoft.Extensions.Hosting.Internal.Host
2024-09-23 19:21:37.4723 Debug Targets not configured for Logger: Microsoft.Hosting.Lifetime
2024-09-23 19:21:37.4738 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer
2024-09-23 19:21:37.4738 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware
2024-09-23 19:21:37.5001 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Core.Internal.CertificatePathWatcher
2024-09-23 19:21:37.5001 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel
2024-09-23 19:21:37.5001 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.BadRequests
2024-09-23 19:21:37.5001 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Connections
2024-09-23 19:21:37.5001 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Http2
2024-09-23 19:21:37.5001 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Http3
2024-09-23 19:21:37.5047 Debug Targets not configured for Logger: Project.App
2024-09-23 19:21:37.6132 Debug Targets not configured for Logger: MassTransit
2024-09-23 19:21:37.6132 Debug Targets not configured for Logger: MassTransit.Messages
2024-09-23 19:21:37.6132 Debug Targets not configured for Logger: MassTransit.SendTransport
2024-09-23 19:21:37.6132 Debug Targets not configured for Logger: MassTransit.ReceiveTransport
2024-09-23 19:21:38.3120 Debug Targets not configured for Logger: Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService
2024-09-23 19:21:38.3148 Debug Targets not configured for Logger: Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService
2024-09-23 19:21:38.3148 Debug Targets not configured for Logger: MassTransit.Transports.BusDepot
2024-09-23 19:21:38.3183 Debug Targets not configured for Logger: Microsoft.AspNetCore.Hosting.Diagnostics
2024-09-23 19:21:38.3692 Debug Targets not configured for Logger: Project.Shared.Data.Database.DatabaseInitializer
2024-09-23 19:21:39.8993 Debug Targets not configured for Logger: Microsoft.AspNetCore.Routing.EndpointMiddleware
2024-09-23 19:21:39.9003 Debug Targets not configured for Logger: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware
2024-09-23 19:21:39.9044 Debug Targets not configured for Logger: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware
2024-09-23 19:21:39.9111 Debug Targets not configured for Logger: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware
2024-09-23 19:21:39.9111 Debug Targets not configured for Logger: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware
2024-09-23 19:21:39.9111 Debug Targets not configured for Logger: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware
2024-09-23 19:21:39.9216 Debug Targets not configured for Logger: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
2024-09-23 19:21:40.6203 Debug Targets not configured for Logger: Microsoft.AspNetCore.Routing.Matching.DfaMatcher
2024-09-23 19:21:40.6526 Debug Targets not configured for Logger: Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider
^C2024-09-23 19:21:44.8625 Debug LogFactory Flush with timeout=15 secs
2024-09-23 19:21:44.8653 Debug Flush completed

Process finished with exit code 0.

And never logs any application logs.

Hopefully that helps. If needed I can try and publish a repo to reproduce the issue.

Copy link

welcome bot commented Sep 23, 2024

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

@snakefoot
Copy link
Contributor

Can you also include the contents of your Program.cs-file with UseNLog() etc.

Or even better attach minimal solution-project that reproduces the issue.

@erikbozic
Copy link
Author

erikbozic commented Sep 23, 2024

Minimal repro here: https://github.com/erikbozic/nlog-repro

Just change the version in Shared.csproj.

@snakefoot
Copy link
Contributor

Thank you for this very detailed bug-report. Have now released NLog.Web.AspNetCore ver. 5.3.14

@erikbozic
Copy link
Author

Thank you for the lightning quick fix!
I tested it with 5.3.14 and it worked!

@snakefoot snakefoot added the bug label Sep 24, 2024
@snakefoot snakefoot transferred this issue from NLog/NLog Sep 24, 2024
@snakefoot
Copy link
Contributor

snakefoot commented Sep 24, 2024

Thank you for the confirmation, that it is now working. And also thank you for reporting this, much appreciated.

Have now created a task #1056 for myself to make an unit-test to ensure the bug doesn't come again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants