serilog-sinks-file
serilog-sinks-file copied to clipboard
Read Log Files While in Use?
This is similar to this issue: https://github.com/serilog/serilog-sinks-file/issues/86
I need to be able to read serilog rolling files while they are active as well as rolled. Can someone give me a definitive answer if this is even possible because I'm seeing some flakiness. Specifically I'm seeing that the files stop getting logged to and/or fail to roll. My seeing as as follows:
{
"Name": "File",
"Args": {
"path": "Logs/Error/error.log",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message} {Properties}{NewLine}{Exception}",
"rollOnFileSizeLimit ": true,
"fileSizeLimitBytes": 10485760,
"shared": true,
"retainedFileCountLimit": 10,
"restrictedToMinimumLevel": "Warning"
}
},
And my reader is using:
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
Have I done everything right? Whatever the answer it would be good to update the docs.
TIA!
What you have there looks right to me; guessing the flakiness is in the workings of the I/O stack (.NET and OS), which can be tricky at times (buffers/flushing/caching of file info...).
If you're able to use a strategy other than file tailing I'd personally go for that, but you might also have luck with a recipe like: https://www.codeproject.com/Articles/7568/Tail-NET
HTH!
Thank you. Yes I have implemented a tail that on-demand reads from the end of the file backwards.
@melmullen Spring cleaning; I'm unclear if there is an outstanding ask here, but closing on the basis that it might be resolved from your pov If you are wrong and feel there's an overall consideration that can be covered by changing the impl and/or documenting something in this repo or the pacckage's readme, please follow-up with either a comment here, or a fresh issue.