-
Notifications
You must be signed in to change notification settings - Fork 1.4k
GZip File Target
Rolf Kristensen edited this page Jan 19, 2026
·
3 revisions
Writes LogEvents to file using GZip compression, by extending the standard NLog File Target.
Platforms Supported: All - Requires nuget-package NLog.Targets.GZipFile
<targets>
<target xsi:type="GZipFile"
name="string"
fileName="Layout"
layout="Layout"
compressionLevel="CompressionLevel"
keepFileOpen="boolean"
enableArchiveFileCompression="boolean"
archiveOldFileOnStartup="boolean"
/>
</targets>- fileName - Name of the file to write to. Layout Required.
-
layout - Text to be rendered. Layout Required.
Default:
${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}
-
compressionLevel - File compression level
-
Optimal- Optimize for small file size -
Fastest- Optimize for speed -
NoCompression- Disables GZip compression
-
-
keepFileOpen - Disables GZip compression when configured to
false. Default:true -
archiveOldFileOnStartup - Disables GZip compression when configured to
false. Default:true
Also inherits all parameters from the standard File-Target.
Linux has the zutils to make it easier to view / tail GZip compressed log-files:
| Tool | Description | Example |
|---|---|---|
| zcat | Decompresses and copies files to standard output. | zcat <path_to_gzipped_log_file> |
| zgrep | Decompresses and searches files for a regular expression. | zgrep -i <path_to_gzipped_log_file> |
| zless | Decompresses and view in pages. | zless <path_to_gzipped_log_file> |
| zmore | Decompresses and view in pages. | zmore <path_to_gzipped_log_file> |
| ztest | Tests integrity of compressed files. | zcat <path_to_gzipped_log_file> |
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json