Description:
I am encountering a System.NotSupportedException when using GZipFileTarget with NLog v6.1.1 and NLog.Targets.GZipFile v6.1.1.
Although Issue #5910 was resolved in v6.0.2 by introducing "counted" file-size to avoid calling GZipStream.get_Length(), the stack trace indicates that get_Length() is still being invoked within FileTarget.OpenNewFileStream.
As a result, logging fails and empty .gz files are being generated in the destination directory. This behavior is very similar to the original report in #5910 where "thousands of empty .gz files" were created.
NLog Version:
NLog: 6.1.1
NLog.Targets.GZipFile: 6.1.1
Platform:
.NET 8.0 (Windows)
Target Configuration (C#):
GZipFileTarget fileTarget = new( "logfile" ) {
Header = headerLayout,
FileName = "${var:logDirectory}\\log.log.gz",
Layout = jsonLayout,
KeepFileOpen = false,
};
Internal Log / Stack Trace:
2026-03-27 12:24:53.6626 Error GZipFileTarget(Name=logfile): Failed writing to FileName: 'D:\Logs\log.log.gz' Exception: System.NotSupportedException: This operation is not supported.
at System.IO.Compression.GZipStream.get_Length()
at NLog.Targets.FileTarget.OpenNewFileStream(String filePath, Int32 bufferSize, Boolean initialFileOpen)
at NLog.Targets.FileTarget.CreateFileStreamWithDirectory(String filePath, Int32 bufferSize, Boolean initialFileOpen)
at NLog.Targets.FileTarget.CreateFileStreamWithRetry(IFileAppender fileAppender, Int32 bufferSize, Boolean initialFileOpen)
at NLog.Targets.FileAppenders.ExclusiveFileLockingAppender..ctor(FileTarget fileTarget, String filePath)
at NLog.Targets.FileTarget.CreateFileAppender(String filePath)
at NLog.Targets.FileTarget.OpenFile(String filename, LogEventInfo firstLogEvent, Nullable`1 previousFileLastModified, Int32 sequenceNumber)
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)
Additional Context:
It appears that the ExclusiveFileLockingAppender or the OpenNewFileStream logic in the base FileTarget is still attempting to check the file length for initialization, which GZipStream does not support.
Description:
I am encountering a System.NotSupportedException when using GZipFileTarget with NLog v6.1.1 and NLog.Targets.GZipFile v6.1.1.
Although Issue #5910 was resolved in v6.0.2 by introducing "counted" file-size to avoid calling GZipStream.get_Length(), the stack trace indicates that get_Length() is still being invoked within FileTarget.OpenNewFileStream.
As a result, logging fails and empty .gz files are being generated in the destination directory. This behavior is very similar to the original report in #5910 where "thousands of empty .gz files" were created.
NLog Version:
NLog: 6.1.1
NLog.Targets.GZipFile: 6.1.1
Platform:
.NET 8.0 (Windows)
Target Configuration (C#):
Internal Log / Stack Trace:
Additional Context:
It appears that the ExclusiveFileLockingAppender or the OpenNewFileStream logic in the base FileTarget is still attempting to check the file length for initialization, which GZipStream does not support.