Skip to content

Commit

Permalink
refactor rolling update code
Browse files Browse the repository at this point in the history
  • Loading branch information
saleem-mirza committed May 31, 2019
1 parent 843a819 commit 3e94df6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static class LoggerConfigurationSQLiteExtensions
/// A switch allowing the pass-through minimum level to be changed at runtime.
/// </param>
/// <param name="maxDatabaseSize">Maximum database file size can grow in MB. Default 10 MB, maximum 20 GB</param>
/// <param name="rollOver">If file size grows past max database size, backup database to new name and create new database file</param>
/// <param name="rollOver">If file size grows past max database size, creating rolling backup</param>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
public static LoggerConfiguration SQLite(
Expand Down
7 changes: 4 additions & 3 deletions src/Serilog.Sinks.SQLite/Sinks/SQLite/SQLiteSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ protected override async Task<bool> WriteLogEventAsync(ICollection<LogEvent> log

var dbExtension = Path.GetExtension(_databasePath);

var newFilePath =
$"{Path.GetFileNameWithoutExtension(_databasePath)}-{DateTime.Now:yyyyMMdd_hhmmss.ff}{dbExtension}";
File.Copy(_databasePath, Path.Combine(Path.GetDirectoryName(_databasePath), newFilePath), true);
var newFilePath = Path.Combine(Path.GetDirectoryName(_databasePath) ?? "Logs",
$"{Path.GetFileNameWithoutExtension(_databasePath)}-{DateTime.Now:yyyyMMdd_hhmmss.ff}{dbExtension}");

File.Copy(_databasePath, newFilePath, true);

TruncateLog(sqlConnection);
await WriteToDatabaseAsync(logEventsBatch, sqlConnection).ConfigureAwait(false);
Expand Down

0 comments on commit 3e94df6

Please sign in to comment.