Skip to content

Commit 4f1ae37

Browse files
Marcin_OsadaMarcin_Osada
Marcin_Osada
authored and
Marcin_Osada
committed
OnFileRemoving will not interfere with Serilog delete
1 parent 57d96c2 commit 4f1ae37

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/Serilog.Sinks.File/Sinks/File/FileLifecycleHooks.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,13 @@ public abstract class FileLifecycleHooks
3737
public virtual Stream OnFileOpened(Stream underlyingStream, Encoding encoding) => underlyingStream;
3838

3939
/// <summary>
40-
/// Method called on log files that were marked as obsolete (old) and by default would be deleted.
41-
/// This can be used to move old logs to archive location or send to backup server
40+
/// Method called on log files that were marked as obsolete (old) and would be deleted.
41+
/// This can be used to copy old logs to archive location or send to backup server
4242
/// </summary>
4343
/// <remarks>
4444
/// Executing long synchronous operation may affect responsiveness of application
4545
/// </remarks>
4646
/// <param name="fullPath">Log file full path</param>
47-
/// <returns>
48-
/// Return if Serilog should delete file.
49-
/// Warning: returning false and keeping file in same place will result in calling this method again in next scan for obsolete files
50-
/// </returns>
51-
public virtual bool OnFileRemoving(string fullPath) => true;
47+
public virtual void OnFileRemoving(string fullPath) {}
5248
}
5349
}

src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ void ApplyRetentionPolicy(string currentFilePath)
199199
var fullPath = Path.Combine(_roller.LogFileDirectory, obsolete);
200200
try
201201
{
202-
if (_hooks == null || _hooks.OnFileRemoving(fullPath))
203-
System.IO.File.Delete(fullPath);
202+
if (_hooks != null) _hooks.OnFileRemoving(fullPath);
203+
204+
System.IO.File.Delete(fullPath);
204205
}
205206
catch (Exception ex)
206207
{

0 commit comments

Comments
 (0)