-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add ZipDaysToKeep to roll-by-size-time appender #564
base: master
Are you sure you want to change the base?
Conversation
…tch the configured naming pattern.
Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits) Signed-off-by: dependabot[bot] <support@github.com>
Bumps [SharpZipLib](https://github.com/icsharpcode/SharpZipLib) from 0.86.0 to 1.2.0. - [Release notes](https://github.com/icsharpcode/SharpZipLib/releases) - [Changelog](https://github.com/icsharpcode/SharpZipLib/blob/master/docs/Changes.txt) - [Commits](https://github.com/icsharpcode/SharpZipLib/commits/v1.2.0) Signed-off-by: dependabot[bot] <support@github.com>
Bumps [ilmerge](https://github.com/dotnet/ILMerge) from 3.0.29 to 3.0.40. - [Release notes](https://github.com/dotnet/ILMerge/releases) - [Commits](https://github.com/dotnet/ILMerge/commits) Signed-off-by: dependabot[bot] <support@github.com>
…tor-1.3.0 Bump coverlet.collector from 1.2.0 to 1.3.0
Bump SharpZipLib from 0.86.0 to 1.2.0
Bump ilmerge from 3.0.29 to 3.0.40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleg-nenashev Any thoughts on the setting name?
|
||
<PropertyGroup Condition="'$(TargetFramework)' != 'netcoreapp3.1'"> | ||
<ILMergeVersion>3.0.40</ILMergeVersion> | ||
<SignAssembly>false</SignAssembly> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes to .csproj files should actually be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
src/Core/WinSWCore/LogAppenders.cs
Outdated
@@ -395,7 +399,7 @@ private void CopyStreamWithRotation(StreamReader reader, string extension) | |||
var nextFileName = Path.Combine(baseDirectory, string.Format("{0}.{1}.#{2:D4}{3}", baseFileName, now.ToString(FilePattern), nextFileNumber, extension)); | |||
File.Move(logFile, nextFileName); | |||
|
|||
writer = CreateWriter(new FileStream(logFile, FileMode.Create)); | |||
writer = CreateWriter(new FileStream(logFile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was an attempt to deal with a sharing violation that was more likely caused by the missing Dispose.
@@ -427,6 +431,7 @@ private void CopyStreamWithRotation(StreamReader reader, string extension) | |||
try | |||
{ | |||
// roll file | |||
writer.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks!
src/Core/WinSWCore/LogAppenders.cs
Outdated
//EventLogger.LogEvent($"{zipFilePath}: datePart matches format {datePart} : {ZipDateFormat}, is older than {ZipDaysToKeep + ZipOlderThanNumDays} days, deleting "); | ||
File.Delete(zipFilePath); | ||
} | ||
//else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't commit comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you mean code that has been commented out?
src/Core/WinSWCore/LogAppenders.cs
Outdated
try | ||
{ | ||
//Get all the zipfiles that might match the naming pattern | ||
List<string> ZipFiles = new List<string>(Directory.GetFiles(directory, zipFileBaseName + ".*.zip")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to instantiate a list. Just use the result array.
The compiler can now optimize foreach
on arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
src/Core/WinSWCore/LogAppenders.cs
Outdated
if (DateTime.TryParseExact(datePart, ZipDateFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime date)) | ||
{ | ||
//the date portion of the name matches the configured ZipDateFormat | ||
if (date.CompareTo(DateTime.Now.AddDays((double)(-ZipDaysToKeep - ZipOlderThanNumDays))) < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the <
operator in C#.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
{ | ||
if (File.Exists(zipFilePath)) | ||
{ | ||
//ZipDateFormat could contain literal characters, including the '.', so this gets a bit tricky |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't TryParseExact
handle .
? It could be a real problem if zipFileBaseName
contains .
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TryParseExact should handle '.', but doesn't seem to like the full file name. Implemented a fix for the possibility of ZipFileBaseName containing '.'
src/Core/WinSWCore/LogAppenders.cs
Outdated
datePart = parts[parts.Length - 1]; | ||
} | ||
//EventLogger.LogEvent($"{zipFilePath}: datePart = {datePart}"); | ||
if (DateTime.TryParseExact(datePart, ZipDateFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime date)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use InvariantCulture
when formatting ZipDateFormat
to string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, CurrentCulture is used when formatting the file name. TryParseExact call changed to match.
Added to my queue |
Implemented a new option on the
RollingSizeTimeLogAppender
that allows configuration of a number of days for which zipped log files should be kept.Fixed issues with log archiving in RollingSizeTimeAppender.