Sorry for my english.
I've created project to teach my team how to migrate simple console app to .core 3.1. All is ok with nlog, all is working as expected. BUT. When i publish as "produce single file" - ${basedir} is not respond to real situation. As i understand - when i run application as single file - dotnet "unpacks" file to temp folder and run from it. In my case log files appeared in C:\TEMP.net\gOldCleaner\lcieddmk.fr0\ when application launched from D:_TEMP\gOld31\
NLog version: 4.6.8
Platform: .NET Core 3.1
Current NLog config
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<variable name="logDirectory" value="${basedir}/logs" />
<targets>
<target name="console" xsi:type="ColoredConsole" layout="${message}" />
<target name="LogFileInOneFile" xsi:type="File" fileName="${logDirectory}/${date:format=yyyy-MM-dd}.log" layout="${longdate}|${pad:padding=5:inner=${level:uppercase=true}}|${message}|${exception:format=ToString,StackTrace}" />
</targets>
<rules>
<logger name="*" minLevel="Info" maxLevel="Info" writeTo="console" />
<logger name="*" minLevel="Debug" writeTo="LogFileInOneFile" />
</rules>
</nlog>
What is the current result?
Application run from
D:_TEMP\gOld31\gOldCleaner.exe but log appears in C:\TEMP.net\gOldCleaner\lcieddmk.fr0\logs
What is the expected result?
Logs appeared in D:_TEMP\gOld31\logs if
<variable name="logDirectory" value="${basedir}/logs" />
Did you checked the Internal log?
yes, and found path C:\TEMP.net\gOldCleaner\lcieddmk.fr0\ :)
Are there any workarounds? yes/no
yes
use absolute path like "c:\logs" instead of ${basedir}/logs
Is there a version in which it did work?
Don't think so, single file publish is enough new feature
Can you help us by writing an unit test?
yes :)
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!
Duplicate of #3517 + #3738
Sadly enough Microsoft decided not to fix AppDomain.BaseDirectory when doing Single File Publish in NetCore 3.1
https://github.com/dotnet/aspnetcore/issues/12621
https://github.com/dotnet/core-setup/issues/7491
The work-around is that you have specify fixTempDir=true explicit so it becomes ${basedir:fixTempDir=true}:
<variable name="logDirectory" value="${basedir:fixtempdir=true}/logs" />
Thank you!
Most helpful comment
Duplicate of #3517 + #3738
Sadly enough Microsoft decided not to fix AppDomain.BaseDirectory when doing Single File Publish in NetCore 3.1
https://github.com/dotnet/aspnetcore/issues/12621
https://github.com/dotnet/core-setup/issues/7491
The work-around is that you have specify
fixTempDir=trueexplicit so it becomes${basedir:fixTempDir=true}: