Description
Description
Related to #152
If using hooks that do not allow reopening a file, it force-creates a new one every 30 minutes for no real reason.
Reproduction
Use the following hook with a RollingFileSink
with any big filesize limit (i.e. 1 GB) and inifite interval rolling:
public override Stream OnFileOpened(Stream underlyingStream, NetEncoding encoding)
{
if (underlyingStream is { CanRead: false, Position: not 0 })
{
throw new IOException("It's not possible to reuse the log file since this requires ReadWrite permission on the stream.");
}
return underlyingStream;
}
Wait for 30 minutes and create a log entry after that (or just reduce the time to 1 millisecond here):
serilog-sinks-file/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs
Lines 115 to 117 in 5e3ff41
Due to the checkpoint being checked on the next log being written, it will enforce a reload, leading to the hook failing in this location:
serilog-sinks-file/src/Serilog.Sinks.File/Sinks/File/RollingFileSink.cs
Lines 95 to 108 in 5e3ff41
Expected behavior
The log file will correctly be used until something goes wrong. It will NOT try to reopen the file every 30 minutes and create a new log file messing up the retention.
Relevant package, tooling and runtime versions
Serilog.Sinks.File 6.0.0
but also tried to self-compile it from dev
Additional context
Due to the issue from #152 it's not possible to reopen files just leasurely. As encryption would need to remove the padding and re-read the IV, it requires ReadWrite
permission. This needs to be enforced for it to work at all. But due to the RollingFileSink
just setting the next checkpoint to 30 minutes if not needed at all, this leads to the issue of retention deleting needed files. There is currently no workaround possible with encryption enabled and using a rolling file sink right now.
Please either fix #152 to support ReadWrite
or at least make sure that the checkpoint is set in a way that does not reopen the file without need to only run into it on restarts instead of every 30 minutes on runtime :) This will at least hit the retention less as restarts aren't happening often.