dfacto-lab / serilog-sinks-file

Serilog file sinks duplicated for file rolling
Apache License 2.0
14 stars 10 forks source link

Exception thrown first time logging when retainedFileCountLimit = 1 #21

Open adamtoner opened 1 year ago

adamtoner commented 1 year ago

The retained file count limit being set to 1 seems to cause a locking issue the first time the file is written to as it is trying to delete and write concurrently.

Internal Error with Serilog: 2023-09-13T09:32:23.6593293Z Error System.IO.IOException: The process cannot access the file '<FILEPATH>\error.log' because it is being used by another process.
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at Serilog.Sinks.PersistentFile.RollingFileSink.ApplyRetentionPolicy(String currentFilePath) while removing obsolete log file <FILEPATH>\error.log