Log4Net - Blocking a process in files

We use Log4Net with FileAppender to log errors during the process. At the end of the process, we want to send a log file by email, but we cannot do this, because Log4Net still has a file lock, and we get a message that the file is being used by another process. Any ideas?

We use the following configuration:

  <appender name="WarnFileAppender" type="log4net.Appender.FileAppender">
    <file value="d:\for-review-log.txt" />

    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %logger - %message%newline" />
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
      <levelMin value="INFO" />
      <levelMax value="WARN" />
    </filter>
    <filter type="log4net.Filter.DenyAllFilter" />
    <appendToFile  value="false"></appendToFile>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  </appender>
+3
source share
2 answers

I assume that the log is some kind of service, so the log will be blocked until the service is started.

You probably want to use a shared lock when reading a file for sending.

Or you can copy the file and send a copy.

+4
source

. Olso , SMTPmailAppender, , , - . , , ( )

0

All Articles