-
Notifications
You must be signed in to change notification settings - Fork 125
Creating log backup file with .bak extension using serilog #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you look back across the issues, you'll see it's well established that files do not get renamed in this manner, in contrast to log4net and NLog. I personally strongly believe this is for the best; some reasons are covered here. Based on this, I'd suggest that this feature is unlikely to make the bar given how it conflicts with the existing behavior and this thinking. |
Yes, I agree this might have implemented for some best reason. I wanted to know if it is possible to do this renaming for log using serilog? In my application user has an option to directly click on "show log". I need a constant log file name throughout my application. |
There is no renaming anywhere in Serilog, so I strongly suspect the answer is a no. Even if you did it yourself, it would conflict with the code's expectation that a file, once started, remains in a stable place. TL;DR No! |
To answer the inevitable follow up - no, there is no way to find out the current log file name at the moment; you could grab the logic from inside Serilog.Sinks.File, and/or ;og a separate ticket proposing to expose the name. The bottom line here though is that the first file might only just have rolled over, in which case you still need to be able to move back to previous ones in a viewer => best to just deal with the facts of how its implemented now - there are plenty pros for the way things are atm, even if your need seems to be more difficult to address than one might hope. |
@RemSann thanks for raising this. I don't think there's a straightforward path to implementing this in the near future - as @bartelink suggests, there's been a long history of discussions around different file naming/rolling strategies 😅 - we're adding some flexibility over time, but don't want to end up with "spaghetti" due to the very wide range of conflicting requirements that come up. In your "show log" feature, you can use the logic in https://github.com/serilog/serilog-sinks-file/blob/dev/src/Serilog.Sinks.File/Sinks/File/PathRoller.cs#L76 to figure out what the latest file in a set might be. Hope this helps; I'm doing some maintenance on this issue tracker so I'll close this ticket as stale, but let us know if you need more info. |
I am using Serilog framework for logging in my application. The file size limit i have given is 2MB. So when the file reaches 2MB, new file is created with like app_001.log, existing app.log is a back up file. But what i want to do is when the file reaches 2MB, it should rename app.log to app.log.bak and write the new logs to newly created app.log file.
_logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File(_filepath, restrictedToMinimumLevel: LogEventLevel.Debug, shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 2000000)
.CreateLogger();
The text was updated successfully, but these errors were encountered: