I am writing a C # program that, using the log4net library, logs to a separate file. When a log file is full, it should be deleted. But, unfortunately, due to the fact that this file is open in the application, I can not delete it. When the File.Delete method is File.Delete from the System.IO.File class, nothing happens, the file is not deleted, and the log continues to be recorded. How can this problem be solved?
- and what does the file overflow mean? - Bald
- I wrote a little wrong. This is just an arbitrary size in bytes, which is set by the user, by which you want to delete the file. - Ramon
- 2log4net, like other smart loggers, can monitor the size of the log itself, and clean it, hit it in size, this is called log rotation, you can configure something, and not bicycling. - Primus Singularis
|
2 answers
Try adding a file to the config:
<lockingmodel type="log4net.Appender.FileAppender+MinimalLock"/> This should help unlock the file for deletion.
|
And why do you carry out such manipulations in the code, when log4net can do it out of the box ?
<maximumFileSize value="1MB" /> |