1

I am logging the data like below :

.WriteTo.File("log.txt", rollOnFileSizeLimit: true,retainedFileCountLimit: 1,
                                             fileSizeLimitBytes: 10)

This creates a file set like this:

log.txt => log_001.txt => log_002.txt

Since I set retainedFileCountLimit = 1 once the log.text was deleted then log_001.txt

Is there any way to maintain only the log.log file instant of keeping int values in an increased format ?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
tesrer
  • 41
  • 5
  • 1
    What do you want to happen when the size limit is reached? If you don't start a new file, you'll have to start overwriting the contents of the existing file, right? How would the contents be overwritten in that situation? Do you want to start dropping the oldest log entries while appending the new ones? – julealgon Jan 13 '23 at 20:07
  • 1
    Some clarification, is your goal to have a single log file period (e.g, don't write to multiple files) or is your goal to only retain the 'first' log file and delete the later ones (which makes no sense). Seriolog does not support arbitrary sized log files. The max log file size is 1GB. – Nick Bailey Jan 13 '23 at 20:08
  • @julealgon when the size limit is reached I was to dropping the oldest log entries while appending the new ones – tesrer Jan 13 '23 at 20:09
  • @NickBailey My goal to have a single log file with a max size of 100MB – tesrer Jan 13 '23 at 20:11
  • @tesrer I doubt that strategy is supported by Serilog. Creating a "circular buffer" text file like you want is actually _extremely_ inefficient: for every log line that would be written past the size limit (at the end of the file), the first entry would need to be removed and then _the entire file contents_ would need to be shifted in memory by the number of characters in the deleted line. Imagine this happening on every single log entry that is written... It would certainly be cool to have "only the last N entries" in the file or what have you, but I don't think a native solution exists. – julealgon Jan 13 '23 at 20:19
  • Rolling cannot be implemented in one text file. If the log entries were fixed-length, then it would be possible to organize a circular buffer, but with a free form text it would hardly be usable. So in this case you'd better have some rolling policy and have more than one file. – Mike Mozhaev Jan 13 '23 at 20:20
  • Also, please update your question title to be a bit more specific about your issue. Right now, it forces everyone to open the link to be able to tell what is it that you need. – julealgon Jan 13 '23 at 20:20

1 Answers1

1

There is a forked sink, Serilog.Sinks.PersistentFile that does this.

But it's a very debatable ask which is why it's not supported by the standard Serilog.Sinks.File for the foreseeable future.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249