How to make a log file with maximum size?

I enter the file using FileStream.Write (). When the file reaches its maximum size, I want to remove the log load from the beginning of the file. What is the best way to do this?

The best idea I got so far is to create a second file. Write everything that I want to keep from the source file. Then delete the source file and rename the second file with the name of the source files.

Is there an easier and more efficient way I can do this?

+3
source share
6 answers

Yes and no; -)

What is important for you: efficiency or simplicity?

. - . /, , == max . , , ... DB " ", . . Yeck!

( , ): , . "" ... , , numLogs == maxLogs .

. .

+3

, , , , .

+1

. "" , . :

  • , , . , ( - ).

  • , . : - , , .

, .

+1

, , . , , - .

, - . , log4net , , .

+1

, , ? max , . .

Of course, it would be even easier if you did not write files at all until the program ends, and at that moment you will write all the cached lines. Although this may not be possible if your program has been running for a long time, and you want to see the log during startup with a tail or something similar.

0
source

Source: https://habr.com/ru/post/1708551/


All Articles