Skip to content

Commit

Permalink
Logging purge for TextFile implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
markhotchkiss committed Dec 13, 2016
1 parent 69309f2 commit bf85f39
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 9 deletions.
Binary file modified .vs/ErrorLogger/v14/.suo
Binary file not shown.
29 changes: 28 additions & 1 deletion MJH.Logger/BusinessLogic/TextLogger/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace MJH.BusinessLogic.TextLogger
{
public class Archive : IArchive
public class Archive : IArchive, ILoggingPurge
{
public void ArchiveLogFile()
{
Expand Down Expand Up @@ -96,5 +96,32 @@ private static int GetMaxLogFile(DirectoryInfo diInfo)

return numberList.Max() + 1;
}

public void Purge()
{
var config = GetConfig();

var directoryInfo = new DirectoryInfo(config.Text.FileInformation.ArchiveDirectory);

var listToRemove = new List<string>();

var fileCount = 0;

foreach (var file in directoryInfo.EnumerateFiles().OrderBy(d => d.LastWriteTime))
{
if (fileCount <= config.Text.LoggerInformation.FileHistoryToKeep)
{
fileCount++;
continue;
}

listToRemove.Add(file.FullName);
}

foreach (var file in listToRemove)
{
File.Delete(file);
}
}
}
}
4 changes: 2 additions & 2 deletions MJH.Logger/LoggerConfig.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<LoggerConfig>
<LoggerType>SQL</LoggerType> <!--TextFile, SQLite, SQL-->
<LoggerType>TextFile</LoggerType> <!--TextFile, SQLite, SQL-->
<LoggingLevel>Debug</LoggingLevel> <!--Debug, Info, Error - NOTE, this is case sensitive-->
<Sql>
<ServerInformation>
Expand Down Expand Up @@ -29,7 +29,7 @@
<ArchiveDirectory>D:\Tests\Logger\Archive</ArchiveDirectory>
</FileInformation>
<LoggerInformation>
<FileHistoryToKeep>5</FileHistoryToKeep>
<FileHistoryToKeep>2</FileHistoryToKeep>
<MaxFileSize>1</MaxFileSize>
</LoggerInformation>
</Text>
Expand Down
2 changes: 2 additions & 0 deletions MJH.Logger/Loggers/TextLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private static void CheckArchive()
}

archive.ArchiveLogFile();

archive.Purge();
}
}
}
2 changes: 1 addition & 1 deletion MJH.Logger/bin/Debug/$RANDOM_SEED$
Original file line number Diff line number Diff line change
@@ -1 +1 @@
685101356
175995522
4 changes: 2 additions & 2 deletions MJH.Logger/bin/Debug/LoggerConfig.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<LoggerConfig>
<LoggerType>SQL</LoggerType> <!--TextFile, SQLite, SQL-->
<LoggerType>TextFile</LoggerType> <!--TextFile, SQLite, SQL-->
<LoggingLevel>Debug</LoggingLevel> <!--Debug, Info, Error - NOTE, this is case sensitive-->
<Sql>
<ServerInformation>
Expand Down Expand Up @@ -29,7 +29,7 @@
<ArchiveDirectory>D:\Tests\Logger\Archive</ArchiveDirectory>
</FileInformation>
<LoggerInformation>
<FileHistoryToKeep>5</FileHistoryToKeep>
<FileHistoryToKeep>2</FileHistoryToKeep>
<MaxFileSize>1</MaxFileSize>
</LoggerInformation>
</Text>
Expand Down
Binary file modified MJH.Logger/bin/Debug/MJH.Logger.dll
Binary file not shown.
Binary file modified MJH.Logger/bin/Debug/MJH.Logger.pdb
Binary file not shown.
Binary file modified MJH.Logger/obj/Debug/MJH.Logger.dll
Binary file not shown.
Binary file modified MJH.Logger/obj/Debug/MJH.Logger.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion MJH.UnitTests/bin/Debug/$RANDOM_SEED$
Original file line number Diff line number Diff line change
@@ -1 +1 @@
685101356
175995522
4 changes: 2 additions & 2 deletions MJH.UnitTests/bin/Debug/LoggerConfig.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<LoggerConfig>
<LoggerType>SQL</LoggerType> <!--TextFile, SQLite, SQL-->
<LoggerType>TextFile</LoggerType> <!--TextFile, SQLite, SQL-->
<LoggingLevel>Debug</LoggingLevel> <!--Debug, Info, Error - NOTE, this is case sensitive-->
<Sql>
<ServerInformation>
Expand Down Expand Up @@ -29,7 +29,7 @@
<ArchiveDirectory>D:\Tests\Logger\Archive</ArchiveDirectory>
</FileInformation>
<LoggerInformation>
<FileHistoryToKeep>5</FileHistoryToKeep>
<FileHistoryToKeep>2</FileHistoryToKeep>
<MaxFileSize>1</MaxFileSize>
</LoggerInformation>
</Text>
Expand Down
Binary file modified MJH.UnitTests/bin/Debug/MJH.Logger.dll
Binary file not shown.
Binary file modified MJH.UnitTests/bin/Debug/MJH.Logger.pdb
Binary file not shown.
Binary file modified MJH.UnitTests/bin/Debug/MJH.UnitTests.dll
Binary file not shown.
Binary file modified MJH.UnitTests/bin/Debug/MJH.UnitTests.pdb
Binary file not shown.
Binary file not shown.
Binary file modified MJH.UnitTests/obj/Debug/MJH.UnitTests.dll
Binary file not shown.
Binary file modified MJH.UnitTests/obj/Debug/MJH.UnitTests.pdb
Binary file not shown.

0 comments on commit bf85f39

Please sign in to comment.