When logging with log4net to a file (using the FileAppender), the FileAppender is holding an exclusive write lock on the file. This doesn’t cause any problems, not even when the application is running with multiple threads, because
log4net should be thread-safe.

This does change however when working with multiple processes, that all share a common log4net configuration and
thus all will utilize the same FileAppender.
This prevents other processes from writing to the file and usually the error "The
process cannot access the file 'xxx.log' because it is being used by another process." will show. In this
case there should not be an exclusive write lock by any process. Fortunately log4net has an appropriate configuration-setting, then all processes will write to the same log file.

?
1
<appendername="LogFileAppender"type="log4net.Appender.RollingFileAppender,log4net">

<lockingModeltype="log4net.Appender.FileAppender+MinimalLock"/>

[...]
</appender>

But acquiring and release locks is quite costly and thus will slow down the overall performance of the application.

An alternative would be to create an individual log per processes. Luckily log4net supports the expansion of variables to generate log-filenames, so we can add the process-id to the filename-pattern.

?
1
2
3
4
<appendername="LogFileAppender"type="log4net.Appender.RollingFileAppender,log4net">
    <filetype="log4net.Util.PatternString"value="Log[%processid]"/>
[...]
</appender>

Logging from multiple processes using log4net的更多相关文章

  1. RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start_processes()

    解决方法: settings中的debug改为false,或者注释掉 参照: https://stackoverflow.com/questions/32521122/cannot-run-in-mu ...

  2. log4net RemotingAppender 的配置

    Before you even start trying any of the alternatives provided, ask yourself whether you really need ...

  3. log4net的各种Appender配置示例

    Apache log4net™ Config Examples Overview This document presents example configurations for the built ...

  4. Apache log4net™ Config Examples

    Overview This document presents example configurations for the built-in appenders. These configurati ...

  5. lockingModel in log4net 日志文件不能被其他进程写入

    http://logging.apache.org/log4net/release/faq.html#single-file How do I get multiple process to log ...

  6. Log4Net 手册

    首先感慨下,现在的程序员做的工作因为高级语言的生产力,系统框架模式的成熟,开源大牛的贡献,已经成越来越偏向 “面向配置编程”了...... 详细使用指南见文章:http://blog.csdn.net ...

  7. Python 中 logging 日志模块在多进程环境下的使用

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python 中 logging 日志模块在多进程环境下的使用 使用 Pytho ...

  8. Log4net - 规则简介

    参考页面: http://www.yuanjiaocheng.net/CSharp/csharprumenshili.html http://www.yuanjiaocheng.net/entity/ ...

  9. Log4net - 项目使用的一个简单Demo

    参考页面: http://www.yuanjiaocheng.net/entity/entitytypes.html http://www.yuanjiaocheng.net/entity/entit ...

随机推荐

  1. Win7 64位VC6调试无法退出

    错误信息:LINK: fatal error LNK1168: cannot open Debug/test1.exe for writing 根据网络上查询,找到最终原因,DM.dll,TLLOC. ...

  2. HTML DOM 事件对象

    HTML DOM 事件对象 由 youj 创建,小路依依 最后一次修改 2016-08-04 HTML DOM 事件 HTML DOM 事件 HTML DOM 事件允许Javascript在HTML文 ...

  3. IDEA工具 常用的设置

    以下均为笔者常用的的设置. 首先选择菜单栏的选项:“File” ----> “settings” 1.字体设置 (1)代码区的字体设置 如下图的选择,"Primary font&quo ...

  4. BZOJ2330或洛谷3275 [SCOI2011]糖果

    BZOJ原题链接 洛谷原题链接 很明显的差分约束,但数据范围较大,朴素\(SPFA\)判正环求解会\(T\)(理论上如此,但我看到有挺多人用朴素的还跑得挺快..),所以需要优化. 我们所建立的有向图中 ...

  5. export export defalut

    require/exports 和 import/export 形式不一样 require/exports 的用法只有以下三种简单的写法: const fs = require('fs') expor ...

  6. day1-windows下python和selenium的安装

    这是一个完整的安装包,下载下来是一个.exe的文件 只需双击,下一步下一步默认安装即可 python从2.7开始都会携带pip插件,做了scripe的环境变量可以,在网络畅通的情况下可以在cmd的命令 ...

  7. LibreOJ #6000. 「网络流 24 题」搭配飞行员 最大匹配

    #6000. 「网络流 24 题」搭配飞行员 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  8. Codeforces 791C. Bear and Different Names 模拟构造

    C. Bear and Different Names time limit per test:1 second memory limit per test:256 megabytes input:s ...

  9. Ubuntu安装bcmath扩展

    sudo apt-get install php-bcmath

  10. ListView 删除item删除不了的问题解决办法

    下面的方法是删除不了item的: Integer pos = Integer.valueOf(msg.getBody().toString()); adapter.getList().remove(p ...