开发者

Stop log4net logging process and remove log file lock

开发者 https://www.devze.com 2023-03-25 20:13 出处:网络
I am working on a windows service application that is supposed to run jobs scheduled at specific times. Each job execution cycle is logged using log4net and has its own file per execution(With 5 jobs

I am working on a windows service application that is supposed to run jobs scheduled at specific times. Each job execution cycle is logged using log4net and has its own file per execution(With 5 jobs running for 5 days once a day there will be 25 log files created).

The question is, how do I stop the log4net log file lock so that once the job has finished execution I can email the log file and delete it from the hard drive?

I need to do this programatically, so the config file setting wou开发者_运维百科ld not work in this case.

I have tried this so far, but it doesn't work:

    logger.Logger.Repository.LevelMap.Clear();
    logger.Logger.Repository.LevelMap.Add(logger.Logger.Repository.LevelMap["OFF"]);


If you're using a FileAppender, you can set the LockingModel to MinimalLock:

Dim fileAppenderTrace As New log4net.Appender.RollingFileAppender
fileAppenderTrace.ImmediateFlush = True
fileAppenderTrace.LockingModel = New FileAppender.MinimalLock()
fileAppenderTrace.ActivateOptions()

It'll release the file after each log entry is written, not after the job is done, so I'm not sure if that's entirely what you're looking for.

0

精彩评论

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

关注公众号