-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
