Closed carlopantaleo closed 3 years ago
Hello,
That’s expected behavior it will roll the file every time you restart your process. If it’s the same day it will append a number on top of the date. If it’s not the same day it will create a new file with the current date. The system doesn’t know when was the last time the file was rolled. 1/ first run -> logFile.log is created 2/ second run on same day -> existing logFile.log is moved to logFile20210512.log 3/ third run on same day -> existing logFile.log is moved to logFile20210512_001.log because logFile20210512.log exists. The system doesn’t merge log files as it doesn’t know if logFile.log and logFile20210512.log have been created the same day 4/ fourth run on same day -> existing logFile.log is moved to logFile20210512_002.log because logFile20210512.log and logFile20210512_001.log exists And so on…
My understanding is that log4net works exactly the same way.
logFile20210512_002.log contains the previous run logs, logFile20210512_001.log contains the previous previous run logs etc….
Logging systems usually don’t merge previous logs in one file, that would require to parse all existing file names, extract date, check if the date is the same as the current date, merge files etc...
This is something you can do when starting your app if you want, on each restart you do some cleaning.
Regards,
http://www.dfacto.ch/ Numa Schmeder www.dfacto.ch http://www.dfacto.ch/ NUMA@DFACTO.CH @.***> | M +41 79 538 30 01
DIGITAL STRATEGY | DESIGN | DEVELOPMENT
Le 12 mai 2021 à 17:24, Carlo Pantaleo @.***> a écrit :
Hello,
firstly, thanks for this Serilog sink as I really missed the similar functionality offered by log4net.
I'm still encountering an issue with this sink, because, when setting a daily rolling interval, on each run of my application during the same day, a new file with a new sequence number is created. For example: logFile.log -> persistent file (that's ok) logFile20210512.log -> rolled file (that's ok) logFile20210512_001.log -> rolled file on second run (that's not ok) logFile20210512_002.log -> rolled file on third run (that's not ok) ...and so on.
What I expected is this: logFile.log -> persistent file logFile20210512.log -> rolled file which contains all the logs of the previous runs (or, better, the logs of the previous day as log4net does).
Thanks in advance for your availability. Carlo
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dfacto-lab/serilog-sinks-file/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZXCF5PPRCEBIWAIPOVBW3TNKMSVANCNFSM44Y2PSZQ.
Hello,
thanks for your reply.
For what I know from my experience with log4net, the exact behaviour is this:
logFile.log
logFile.log
is renamed into logFile20210512.log
(which is logFile<D-1>.log
). A new logFile.log
is created and every run is then appended to it.I think log4net checks the "last modified date" to understand when to roll files, but it's just a supposition. Surely what PerstistentFile does is trivial to not be afraid of losing log files.
Regards, Carlo
Hello,
This is exact same behavior. And with log4net, if you restart multiple time your process the same day it will recreate many files as does this version of serilog-fils-sink… I have it in production on multiple servers since 2 years, and it rolls perfectly every day.
Regards,
http://www.dfacto.ch/ Numa Schmeder www.dfacto.ch http://www.dfacto.ch/ NUMA@DFACTO.CH @.***> | M +41 79 538 30 01
DIGITAL STRATEGY | DESIGN | DEVELOPMENT
Le 13 mai 2021 à 08:28, Carlo Pantaleo @.***> a écrit :
Hello,
thanks for your reply.
For what I know from my experience with log4net, the exact behaviour is this:
On first day, each run is appendend to logFile.log On next day, existing logFile.log is renamed into logFile20210512.log (which is logFile
.log). A new logFile.log is created and every run is then appended to it. I think log4net checks the "last modified date" to understand when to roll files, but it's just a supposition. Surely what PerstistentFile does is trivial to not be afraid of losing log files. Regards, Carlo
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dfacto-lab/serilog-sinks-file/issues/9#issuecomment-840341288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZXCF7JGYENGABHDBPP4C3TNNWQBANCNFSM44Y2PSZQ.
Not really... It rolls perfectly if the application is always running or runs once per day, but not if it runs multiple times per day. What I'm trying to achieve is the same as using a log4net appender configured like this:
<appender name="RollingRequestFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\logFile.log" />
<staticLogFileName value="true" />
<rollingStyle value="Date" />
<datePattern value=".yyyyMMdd" />
<maxSizeRollBackups value="10" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%3.3thread] | %message%newline" />
</layout>
</appender>
Anyways, the current behaviour of the sink is fine, it surely brings a great improvement over the standard File
sink. Mine was just a suggestion for people who were looking for the exact same behavior of log4net.
Well, this could an improvement, if you have a patch to submit, I would be happy to look at it.
Best regards
http://www.dfacto.ch/ Numa Schmeder www.dfacto.ch http://www.dfacto.ch/ NUMA@DFACTO.CH @.***> | M +41 79 538 30 01
DIGITAL STRATEGY | DESIGN | DEVELOPMENT
Le 13 mai 2021 à 17:05, Carlo Pantaleo @.***> a écrit :
Not really... It rolls perfectly if the application is always running or runs once per day, but not if it runs multiple times per day. What I'm trying to achieve is the same as using a log4net appender configured like this:
Anyways, the current behaviour of the sink is fine, it surely brings a great improvement over the standard File sink. Mine was just a suggestion for people who were looking for the exact same behavior of log4net.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dfacto-lab/serilog-sinks-file/issues/9#issuecomment-840624016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZXCF2BLLKPM27RPYV5MGLTNPTELANCNFSM44Y2PSZQ.
The new version is deployed, I created a tag 4.1.1-beta that contains your changes. A nuget package has been deployed. If you are ok I will close this issue.
Sure! Thanks very much for merging my changes.
Hello,
firstly, thanks for this Serilog sink as I really missed the similar functionality offered by log4net.
I'm still encountering an issue with this sink, because, when setting a daily rolling interval, on each run of my application during the same day, a new file with a new sequence number is created. For example:
logFile.log
-> persistent file (that's ok)logFile20210512.log
-> rolled file (that's ok)logFile20210512_001.log
-> rolled file on second run (that's not ok)logFile20210512_002.log
-> rolled file on third run (that's not ok) ...and so on.What I expected is this:
logFile.log
-> persistent filelogFile20210512.log
-> rolled file which contains all the logs of the previous runs (or, better, the logs of the previous day as log4net does).Thanks in advance for your availability. Carlo