开发者

Log4Net - Process Lock on Files

We're using Log4Net with a FileAppender to log errors during a process. As the process is finishing, we want to email the log file but we can't do that as it Log4Net still has a lock on the file and we get a message that the file is in use by another process. Any ideas?

We're using a config like this:

  <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>
    <fi开发者_运维知识库lter 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>


I assume log is from some kind of service, so the log will be locked until service is running.

You probably want to use shared lock while reading the file for sending.

Or you can copy the file and send the copy.


ive got the same problem. Olso a flush doesn't work and when i try to use the SMTPmailAppender that olso doesn't seem to work somehow. but when i use my own created class to send email it works, only he doesn't add the attachment(logfile)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜