In my WCF / C# project, I am using Nlog, it successfully creates logs inside the current date folder, but it does not archive the log files.
NLog.config:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="false"
internalLogFile="c:\temp\nlog-internal.log"
internalLogLevel="Trace"
>
<targets>
<!-- Logs will go into Logs folder -->
<target xsi:type="File"
name="file"
fileName="Logs/${shortdate}/Test.log"
createDirs="true"
layout="${longdate}|${level:uppercase=true}|${callsite}|[${threadid}]|${message}${exception:format=tostring}"
keepFileOpen="false"
archiveEvery="Day"
archiveFileName="Logs/Test_${shortdate}.log"
/>
</targets>
<rules>
<logger name="Test.*" minlevel="Info" writeTo="file" />
</rules>
</nlog>
I want that if system ran on today 03/10/2025, and does not restarted on next day the log file should be moved outside from the dated folder.
Consider the actual date for this test: October 3rd 2025.
If I run my app now, the folder 2025-10-03 and inside that folder file Test.log will be created in the Log folder.
.
├── ...
├── Logs
│ └── 2025-10-03
└── Test.log
└── ...
If I send a request to my app next day without restarting the app, the file above will be archived to outside the dated folder and a new folder and file will be created in the Log folder.
.
├── ...
├── Logs
│ └── 2025-10-03
└──
│ └── 2025-10-04
└── Test.log
│ └── Test_2025-10-04.log
└── ...