Skip to content

Commit

Permalink
Purge added for SQLite.
Browse files Browse the repository at this point in the history
  • Loading branch information
markhotchkiss committed Dec 13, 2016
1 parent a5cdf4f commit 69309f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Binary file modified .vs/ErrorLogger/v14/.suo
Binary file not shown.
20 changes: 16 additions & 4 deletions MJH.Logger/BusinessLogic/Sqlite/LoggingSqlite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@

namespace MJH.BusinessLogic.Sqlite
{
internal class LoggingSqlite : ILoggingWriter
internal class LoggingSqlite : ILoggingWriter, ILoggingPurge
{
private readonly string _dbName;
private readonly string _dbLocation;

private readonly SQLiteConnection _dbConnection;
private readonly string _databasePassword = string.Empty;

private readonly LoggerConfig _config;

public LoggingSqlite()
{
var config = new ConfigurationHandler().Read();
_config = new ConfigurationHandler().Read();

_dbName = config.SQLite.ServerInformation.LogFileName;
_dbLocation = config.SQLite.ServerInformation.LogFileLocation;
_dbName = _config.SQLite.ServerInformation.LogFileName;
_dbLocation = _config.SQLite.ServerInformation.LogFileLocation;

_dbConnection = new SQLiteConnection($"Data Source={_dbLocation + "\\" + _dbName};Version=3;Password={_databasePassword};");
}
Expand Down Expand Up @@ -62,5 +64,15 @@ public void Write(string loggingLevel, LoggingTypeModel.LogCategory logCategory,
{
ExecuteSqLiteNonQuery($"INSERT INTO Error VALUES(NULL,'{loggingLevel}','{logCategory}','{error}','{dateTime:yyyy-MM-dd HH:mm:ss}')");
}

public void Purge()
{
if (_config.SQLite.LoggerInformation.HistoryToKeep == 0)
{
return;
}

ExecuteSqLiteNonQuery($"DELETE FROM Error WHERE DateTimeUTC < GETDATE()-{_config.SQLite.LoggerInformation.HistoryToKeep}");
}
}
}

0 comments on commit 69309f2

Please sign in to comment.