Repository navigation
Closed
Labels
file-archivingIssues with archiving with the file targetIssues with archiving with the file targetfile-targetquestion
Milestone
Description
NLog version: 6.0.1
Platform: .NET Framework 4.8
Current NLog config
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
internalLogFile="c:\temp\nlog-internal.log"
internalLogLevel="Debug">
<extensions>
<add assembly="NLog.Targets.GZipFile"/>
</extensions>
<targets async="true">
<target xsi:type="GZipFile"
name="generalLogFile"
layout="${longdate}|${level:uppercase=true}|${threadid}|${logger}|${message}|${replace-newlines:${exception:format=ToString,Data}}"
fileName="${specialfolder:folder=CommonApplicationData:cached=true}\Scanacon\SA80\Logs\SA80_Logs.gz
archiveFileName="${specialfolder:folder=CommonApplicationData:cached=true}\Scanacon\SA80\Logs\Archive\SA80_Logs.gz"
archiveSuffixFormat="_{1:yyyyMMdd}_{0:000}"
archiveEvery="Day"
archiveAboveSize="104800"
maxArchiveDays="30"
compressionLevel="Optimal"/>
<target xsi:type="GZipFile"
name="dcuLogFile"
layout="${longdate}|${level:uppercase=true}|${threadid}|${logger}|${message}|${replace-newlines:${exception:format=ToString,Data}}"
archiveFileName="${specialfolder:folder=CommonApplicationData:cached=true}\Scanacon\SA80\Logs\Archive\SA80_DCU_Logs.gz"
fileName="${specialfolder:folder=CommonApplicationData:cached=true}\Scanacon\SA80\Logs\SA80_DCU_Logs.gz"
archiveSuffixFormat="_{1:yyyyMMdd}_{0:000}"
archiveEvery="Day"
archiveAboveSize="104800"
maxArchiveDays="30"
compressionLevel="Optimal"/>
</targets>
<rules>
<logger name="*DCU*" minlevel="Warn" writeTo="generalLogFile,dcuLogFile" ruleName="dcuGeneralLogFileRule" final="true"/>
<logger name="*DCU*" minlevel="Trace" writeTo="dcuLogFile" ruleName="dcuLogFileRule" final="true"/>
<logger name="*" minlevel="Trace" writeTo="generalLogFile" ruleName="generalLogFileRule"/>
<logger name="*" minlevel="Trace" writeTo="dcuLogFile"/>
</rules>
</nlog>
- What is the current result?
Logging doesn't work and thousands of empty .gz files are created.
- Did you checked the Internal log?
- Please post full exception details (message, stacktrace, inner exceptions)
2025-07-01 14:51:08.4578 Error GZipFileTarget(Name=generalLogFile_wrapped): Failed writing to FileName: 'C:\ProgramData\Scanacon\SA80\Logs\SA80_Logs.gz' Exception: System.NotSupportedException: This operation is not supported.
at System.IO.Compression.GZipStream.get_Length()
at NLog.Targets.FileAppenders.ExclusiveFileLockingAppender.get_FileSize()
at NLog.Targets.FileTarget.MustArchiveBySize(IFileAppender fileAppender)
at NLog.Targets.FileTarget.MustArchiveFile(IFileAppender fileAppender, LogEventInfo firstLogEvent)
at NLog.Targets.FileTarget.RollArchiveFile(String filename, OpenFileAppender openFile, LogEventInfo firstLogEvent, Boolean hasWritten)
at NLog.Targets.FileTarget.WriteBytesToFile(String filename, LogEventInfo firstLogEvent, MemoryStream ms)
at NLog.Targets.FileTarget.WriteLogEventsToFile(String filename, IList`1 logEvents)
at NLog.Targets.FileTarget.Write(IList`1 logEvents)
- Are there any workarounds?
No
The reason I want to archive file above a specific size (say 100Mb, NLog.config above has small size for testing) is because my application is log intensive and text files bigger than say 100Mb are slow/impossible to open with some applications thus making them pretty much useless (unless chopped in multiple files but that's an extra step to perform).
I also have to work with limited storage spaces on my machines which is why I want to compress the archives.
Metadata
Metadata
Assignees
Labels
file-archivingIssues with archiving with the file targetIssues with archiving with the file targetfile-targetquestion
Type
Fields
Priority
None yet

Activity
snakefoot commentedon Jul 1, 2025
Thank you for the feedback, and happy that NLog.Targets.GZipFile is useful.
I don't see an easy way of retrieving the actual filesize of a compressed GZip-file (without performance overhead). But NLog supports "counted" filesize where NLog keeps track of how much data (uncompressed) have been written to a single file. This allows NLog to roll when ex. 100 MByte have been written to the GZip-file (ex. compressed to 50 MByte actual filesize).
I have created #5911 that allows NLog.Targets.GZipFile to also rely on "counted" file-size. Preview-build is available here:
.zipto.nupkg. Both NLog and NLog.Targets.GZipFile must be updated)Maxyx commentedon Jul 3, 2025
Thank you for the quick support !
Sorry for taking some time to reply, took me time to get back in a state where I could test this.
So far the archiving based on file size is working.
I still need to test if the archiving based on day (archiveEvery="Day") is working. I'll come back to you tomorrow.
Thanks again for such a quick support.
snakefoot commentedon Jul 3, 2025
Happy to hear that
archiveAboveSizeis now working with GZipFile. Believe thatarchiveEvery="Day"should work just fine, since the file-timestamps are not extracted from the GZipStream.It will probably take a few weeks before the next NLog-release, but any early feedback is most welcome.
snakefoot commentedon Jul 9, 2025
Closing as resolved with #5911, which will be released with NLog v6.0.2
snakefoot commentedon Jul 20, 2025
NLog v6.0.2 has been released:
Thank you again for the feedback