-
Notifications
You must be signed in to change notification settings - Fork 125
Feature/initial attempt #72
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f17cb52
initial serilog commit
fbeb47b
intial comments
28a52d6
test comment for reference
360de64
comments made around where to do compression
11f9662
comments on placement of compression
834b1b8
location to do compression o previous file
6a2884f
updates to comments on new method
1027296
file creation and deletion based off previous log
1e27cd8
basic zipping of previous log file at roll
62aca49
added parameters to rolling class, zip type set up in method
814e17f
paramters set up for compression and compression type
b2f32cf
GZIP method set up
67c1153
layout for gzip method set up
d58afda
gzip attempt
99f27a1
GZip basic functionality
9493330
check for uncompressd files and compress
c259969
remove compression bool
636b9f2
new Xunit file, error adding
fddd376
test written for checking compresison, need to delete extra created file
558fb65
log file still in use
64411b7
tests running, disposes log object now
91053dc
moved compression to new file
0be2657
initial commit of work on remote repo
14f3440
moved compression type into src
2d83c64
removed comments from methods
7489f97
moved compression tests into their own file
9a06121
added Assert that original .txt file is deleted in compression, roll
4b5ee31
completed initial PR comments, will resolve the rest on wednesday
a76b65b
updated for comments I did not have questions on / could implement now
4ccea1d
intial method to compress file in chunks for GZip
1325fa3
comments added to gzip method with current functionality
07b897a
updated gzip compress method to use chunking correctly
3b90756
add default value for compression type
5049097
replaced while loop with CopyTo() method
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,14 +70,18 @@ CompressionType compressionType | |
_rollOnFileSizeLimit = rollOnFileSizeLimit; | ||
} | ||
|
||
/// <summary> | ||
/// Chooses which compression algorithm to run on the log file passed in within the given directory. | ||
/// </summary> | ||
/// <param name="logFile"> The log file to be compressed </param> | ||
/// <param name="logDirectory"> The directory that holds logFile </param> | ||
/// <param name="compressionType"> The compression algorithm to be used. Is of type CompressionType </param> | ||
public void Compress(string logFile, string logDirectory, CompressionType compressionType) | ||
{ | ||
var readDirectory = Path.Combine(logDirectory, "new_dir"); | ||
|
||
{ | ||
switch (compressionType) | ||
{ | ||
case CompressionType.Zip: | ||
ZipCompress(logFile, logDirectory, readDirectory); | ||
ZipCompress(logFile, logDirectory); | ||
break; | ||
case CompressionType.GZip: | ||
GZipCompress(logFile, logDirectory); | ||
|
@@ -87,39 +91,51 @@ public void Compress(string logFile, string logDirectory, CompressionType compre | |
} | ||
} | ||
|
||
public void ZipCompress(string prevLog, string logDirectory, string readDirectory) | ||
/// <summary> | ||
/// Uses Zip compression to compress prevLog into a new, zipped directory. | ||
/// The Zip algorithm is from System.IO.Compression | ||
/// </summary> | ||
/// <param name="logFile"> The log file to be compressed </param> | ||
/// <param name="logDirectory"> The directory that holds logFile </param> | ||
public void ZipCompress(string logFile, string logDirectory) | ||
{ | ||
var readDirectory = Path.Combine(logDirectory, "new_dir"); | ||
Directory.CreateDirectory(readDirectory); | ||
System.IO.File.Move( | ||
Path.Combine(logDirectory, prevLog), Path.Combine(readDirectory, prevLog) | ||
Path.Combine(logDirectory, logFile), Path.Combine(readDirectory, logFile) | ||
); | ||
|
||
var zipName = prevLog.Remove(prevLog.Length - 4); | ||
var zip_path = Path.Combine(logDirectory, $"{zipName}-Zip.zip"); | ||
var zipName = Path.GetFileNameWithoutExtension(logFile); | ||
var zip_path = Path.Combine(logDirectory, $"{zipName}.zip"); | ||
System.IO.Compression.ZipFile.CreateFromDirectory(readDirectory, zip_path); | ||
|
||
Directory.Delete(readDirectory, true); | ||
} | ||
|
||
public void GZipCompress(string prevLog, string logDirectory) | ||
/// <summary> | ||
/// Uses GZip compression algorithm to compress logFile into a .gzip file | ||
/// The GZip algorithm is from System.IO.Compression | ||
/// </summary> | ||
/// <param name="logFile"> The log file to be compressed </param> | ||
/// <param name="logDirectory"> The directory that holds logFile </param> | ||
public void GZipCompress(string logFile, string logDirectory) | ||
{ | ||
var logPath = Path.Combine(logDirectory, prevLog); | ||
byte[] byteArray; | ||
using (FileStream prevLogStream = new FileStream(logPath, FileMode.Open)) | ||
{ | ||
byteArray = new byte[prevLogStream.Length]; | ||
prevLogStream.Read(byteArray, 0, (int)prevLogStream.Length); | ||
} | ||
var logPath = Path.Combine(logDirectory, logFile); | ||
byte[] byteArray = new byte[] { }; | ||
|
||
byteArray = System.IO.File.ReadAllBytes(logPath); | ||
|
||
var logName = prevLog.Remove(prevLog.Length - 4); | ||
var GZipPath = Path.Combine(logDirectory, $"{logName}-GZip.gz"); | ||
var logName = Path.GetFileNameWithoutExtension(logFile); | ||
var GZipPath = Path.Combine(logDirectory, $"{logName}.gz"); | ||
|
||
using (FileStream outFile = new FileStream(GZipPath, FileMode.Create)) | ||
using (System.IO.Compression.GZipStream gzipStream = new System.IO.Compression.GZipStream(outFile, System.IO.Compression.CompressionMode.Compress, false)) | ||
{ | ||
gzipStream.Write(byteArray, 0, byteArray.Length); | ||
} | ||
|
||
System.IO.File.WriteAllBytes(GZipPath, byteArray); | ||
|
||
System.IO.File.Delete(logPath); | ||
} | ||
|
||
|
@@ -174,7 +190,8 @@ void AlignCurrentFileTo(DateTime now, bool nextSequence = false) | |
{ | ||
var directoryFileName = Path.GetFileName(directoryFile); | ||
|
||
if (!(directoryFileName.Contains("-GZip"))) | ||
// Not sure if we can assume log files will always be .txt? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope 😄 The filename (and extension) are configurable by the user |
||
if (System.IO.Path.GetExtension(directoryFileName) == ".txt") | ||
{ | ||
Compress(directoryFileName, logDirectory, _compressionType); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
public
?