Ivaylo Penev
Ivaylo Penev

Reputation: 21

Single log file

I would like to have a single log file that will be rolled on the size limit, previous file will be removed so there is only one log file at a time. Exaxmple:

logs.txt raches 10MB --> delete logs.txt start writing to logs_001.txt

My current code is:

            Log.Logger = new LoggerConfiguration()
                .WriteTo.File(
                    LogFile,
                    rollOnFileSizeLimit: true,
                    retainedFileCountLimit: 1,
                    fileSizeLimitBytes: 10485760) //10MB
                .CreateLogger();

The code is from a Xamarin Forms project and it's executed every time the application is initialized.

The issue with that code is that on each application initialization a new log file is created, the previous one is deleted but the file size limit is not respected. So if the log file size is lower than 10MB it will still roll to a new file at each start of the application.

Upvotes: 1

Views: 486

Answers (1)

Ivaylo Penev
Ivaylo Penev

Reputation: 21

The solution was to simply remove rollOnFileSizeLimit: true

Upvotes: 1

Related Questions