Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clear log4net log file?

Tags:

c#

log4net

I am working with log4net. I wants to add a button in my GUI that when the user click on that button, the log file will cleared. How can I do that?

Thanks alot

like image 938
Amir Brand Avatar asked Jul 29 '12 12:07

Amir Brand


2 Answers

I had this issue, too.

You need this in your config:

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
like image 159
chrismead Avatar answered Sep 29 '22 03:09

chrismead


It is not supported "out of the box" from log4net. However, you could using the RollingFileAppender and create a manual class/method to clean up/delete the log file.

For reference, Log4Net: set Max backup files on RollingFileAppender with rolling Date

Another approach to avoid the file being locked would be to set the minimal locking level on the log file via:

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> 
like image 28
Seany84 Avatar answered Sep 29 '22 03:09

Seany84