http://logging.apache.org/log4net/release/faq.html#single-file

How do I get multiple process to log to the same file?

Before you even start trying any of the alternatives provided, ask yourself whether you really need to have multiple processes log to the same file, then don't do it ;-).

FileAppender offers pluggable locking models for this usecase but all existing implementations have issues and drawbacks.

By default the FileAppender holds an exclusive write lock on the log file while it is logging. This prevents other processes from writing to the file. This model is known to break down with (at least on some versions of) Mono on Linux and log files may get corrupted as soon as another process tries to access the log file.

MinimalLock only acquires the write lock while a log is being written. This allows multiple processes to interleave交错 writes to the same file, albeit即使 with a considerable loss in performance.

InterProcessLock doesn't lock the file at all but synchronizes using a system wide Mutex. This will only work if all processes cooperate (and use the same locking model). The acquisition and release of a Mutex for every log entry to be written will result in a loss of performance, but the Mutex is preferable to the use of MinimalLock.

If you use RollingFileAppender things become even worse as several process may try to start rolling the log file concurrently. RollingFileAppender completely ignores the locking model when rolling files, rolling files is simply not compatible with this scenario.

A better alternative is to have your processes log to RemotingAppenders. Using the RemoteLoggingServerPlugin (or IRemoteLoggingSink) a process can receive all the events and log them to a single log file. One of the examples shows how to use the RemoteLoggingServerPlugin.

默认的log4net的lock配置是写独占的

在appender中,配置lock 如下

<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>

就可以确保其他进程可以操作文件

但是不足之处是,会有性能问题

https://stackoverflow.com/questions/1999382/intermittent-log4net-rollingfileappender-locked-file-issue

最新文章

  1. get( )与getline( )区别
  2. C#中如何利用操作符重载和转换操作符
  3. 编写类String的构造函数、析构函数和赋值函数
  4. 三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)
  5. ORACLE 五种表的优缺点总结
  6. C# 几个特殊运算符的理解和Nullable&lt;T&gt; 的研究
  7. Beta冲刺NO.2
  8. H5真机调试
  9. linux 学习笔记 执行脚本篇章
  10. iOS - UIView属性hidden, opaque, alpha, opacity的区别
  11. word如何替换行首?
  12. VC++环境下单文档SDI与OpenGL多视图分割窗口的实现-类似3DMAX的主界面
  13. wcf中的使用全双工通信(转)
  14. Telephone interview with Youyou Tu
  15. varchar(n)跟varchar(max)的区别
  16. JBPM4.4学习笔记
  17. MySQL性能优化的20+条经验
  18. VMware8安装MacOS 10.8
  19. 让网页在ie浏览器下以最高版本解析网页
  20. 用pypy运行ryu

热门文章

  1. 第一章----python简介
  2. Web API 2中的操作结果
  3. Unity3d 重力感应
  4. 43、android:screenOrientation
  5. iptables 实际操作 之 规则查询 2
  6. TP系统常量信息
  7. 解决一个项目里面加载两个同名不同版本的DLL的问题
  8. 使用 Docker 部署 MongoDB 复制集
  9. delphi下excel的操作
  10. django项目部署在Apache服务器中,静态文件路径的注意点