Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

mmatt1967
Copy link

@mmatt1967 mmatt1967 commented Jun 26, 2020

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.

src/Core/WinSWCore/LogAppenders.cs Outdated Show resolved Hide resolved
src/Core/ServiceWrapper/winsw.csproj Show resolved Hide resolved
mmatt1967 and others added 8 commits June 27, 2020 13:47
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 [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
@nxtn nxtn self-requested a review June 27, 2020 15:33
@nxtn nxtn added this to the 2.Next milestone Jun 27, 2020
Copy link
Contributor

@nxtn nxtn left a 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>
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

//EventLogger.LogEvent($"{zipFilePath}: datePart matches format {datePart} : {ZipDateFormat}, is older than {ZipDaysToKeep + ZipOlderThanNumDays} days, deleting ");
File.Delete(zipFilePath);
}
//else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit comments.

Copy link
Author

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?

try
{
//Get all the zipfiles that might match the naming pattern
List<string> ZipFiles = new List<string>(Directory.GetFiles(directory, zipFileBaseName + ".*.zip"));
Copy link
Contributor

@nxtn nxtn Aug 16, 2020

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

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)
Copy link
Contributor

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#.

Copy link
Author

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
Copy link
Contributor

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 ..

Copy link
Author

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 '.'

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))
Copy link
Contributor

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?

Copy link
Author

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.

@oleg-nenashev
Copy link
Member

Added to my queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants