-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the archive-filename as name of file-entry in the compressed zip file #4189
Conversation
Thanks for opening this pull request! |
Kudos, SonarCloud Quality Gate passed! |
This change makes a lot of sense, but is ofcourse a breaking change, and will have to wait for NLog 5.0 I guess the FileTarget can eat one more bullet, but I think it would be nice if the FileTarget was stripped from any copy/move/delete/compress-logic. Instead the file-manipulation-logic should be implemented using one (or more) FileTargetWrapper. See also #2732 and #1249 |
Closing and reopening to rebuild on Travis. |
Besides being a behavior breaking change, then it also breaks the I guess very few have made override of the |
Thanks, This seems a bit excessive, but I'll do it if you think it's necessary. |
I was thinking 3 items:
The do the following:
|
I see, |
Like that work-around. Replacing interface and guiding users to the new-interface generates a lot of code-bloat. Notice that you can also assign your own IFileCompressor for NLog 4.5 with the wanted behavior. While waiting for NLog 5. |
Great, I've made the change - the interface remain unchanged. this is tested and working as expected. |
Very elegant solution. I like it. Tried to figure out whether there was any special reasons for the initial solution (with static filename). But it seems it was just hacked together until it worked, without much consideration about entry-filename. But still breaking change so waiting for NLog 5.0 |
@TalAloni Could you extend one of the existing unit-test to verify that the entry-filename is as expected? (Then you will also have better gurantee that it doesn't break in the future). |
@TalAloniI would prefer that |
This would mean adding an additional parameter to AssertZipFileContents (archiveFileName or entryName) and update a few dozens existing tests. |
I can now see that I have given wrong advice. The FileCompressor-property is a static property, so having a single FileTarget changing properties on this static-instance will not work well, when using multiple FileTargets in the same NLog.config. So the entry-name must be given as input-parameter when calling the IFileCompressor. To provide safe passage, then a V2-interface must be introduced (that includes the method with entry-name-parameter). And then call this people when the static-instance implements the V2-interface (else call the old interface-method). |
"So the entry-name must be given as input-parameter when calling the IFileCompressor" "To provide safe passage, then a V2-interface must be introduced" |
This will also do: if (FileCompressor is ZipArchiveFileCompressor defaultCompressor && ArchiveNumbering != ArchiveNumberingMode.Rolling)
{
string entryFileName = Path.GetFileNameWithoutExtension(archiveFileName) + Path.GetExtension(fileName);
defaultCompressor.CompressFile(fileName, archiveFileName, entryFileName); // internal method
}
else
{
FileCompressor.CompressFile(fileName, archiveFileName);
} Skipping the V2-interface |
I've made the requested changes. I've added a new interface extending the existing interface to improve extendibility. |
Thanks, |
The NLog FileTarget has so many door-knobs that it is difficult for normal users to figure out how to use them. Several of the door-knobs are counter intuitive, and make normal users think the NLog FileTarget is broken. Adding more public door-knobs will not improve the situation. Like I said initially "I guess the FileTarget can eat one more bullet, but I think it would be nice if the FileTarget was stripped" (down). |
SonarCloud Quality Gate failed. |
Hooray your first pull request is merged! Thanks for the contribution! Looking for more? 👼 Please check the up-for-grabs issues - thanks! |
Sorry for taking so long to get this pull-request merged. But very grateful for the unit-tests, they have been missing since the zip-feature was introduced. Maybe one day a champion will arrive that will carve the NLog FileTarget into smaller pieces, so it will be easier to maintain and with improved platform compability. |
Thanks for the great and very useful project! |
Updated the wiki: https://github.com/NLog/NLog/wiki/File-target |
This PR sets the entry name for the filename inside the zip (when compression is enabled) according to the archiveFileName format.
Motivation: I have recently enabled compression and found myself in a situation where I cannot mass-extract archived log files to the same directory because they are all using the same filename inside the archive. it seems to me that the rules for the archive filename should also apply to the entry name inside the archive.
Simply put, I expect that once I extract the zip files, I will have the same filenames that I had before enabling compression.
Additional information:
I have worked with the following configuration
Now I wish to enable compression using the following configuration: