Logging from multiple processes using log4net
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
|
< lockingModel type = "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
|
< appender name = "LogFileAppender" type = "log4net.Appender.RollingFileAppender,log4net" > < file type = "log4net.Util.PatternString" value = "Log[%processid]" /> [...] </ appender > |
Logging from multiple processes using log4net的更多相关文章
- 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 ...
- log4net RemotingAppender 的配置
Before you even start trying any of the alternatives provided, ask yourself whether you really need ...
- log4net的各种Appender配置示例
Apache log4net™ Config Examples Overview This document presents example configurations for the built ...
- Apache log4net™ Config Examples
Overview This document presents example configurations for the built-in appenders. These configurati ...
- lockingModel in log4net 日志文件不能被其他进程写入
http://logging.apache.org/log4net/release/faq.html#single-file How do I get multiple process to log ...
- Log4Net 手册
首先感慨下,现在的程序员做的工作因为高级语言的生产力,系统框架模式的成熟,开源大牛的贡献,已经成越来越偏向 “面向配置编程”了...... 详细使用指南见文章:http://blog.csdn.net ...
- Python 中 logging 日志模块在多进程环境下的使用
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python 中 logging 日志模块在多进程环境下的使用 使用 Pytho ...
- Log4net - 规则简介
参考页面: http://www.yuanjiaocheng.net/CSharp/csharprumenshili.html http://www.yuanjiaocheng.net/entity/ ...
- Log4net - 项目使用的一个简单Demo
参考页面: http://www.yuanjiaocheng.net/entity/entitytypes.html http://www.yuanjiaocheng.net/entity/entit ...
随机推荐
- 编码补充 daty 6
---恢复内容开始--- 1. 用id求内存地址 id 查询内存地址 name = 'alex' print(id(name)) li = [1,2,3] print(id(li)) 结果: 2. ...
- Vue 初始化多个Vue 及之间的相互修改
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Jenkins发送邮件,邮件正文嵌套的html中文显示乱码
解决方案: 1.添加系统变量.变量名:JAVA_TOOL_OPTIONS变量值:-Dfile.encoding=UTF8 2.打开jenkins,系统管理--系统设置,在全局属性处勾选Environm ...
- Linux_(4)Shell编程(下)
五.shell流程控制1.一重分支if 语句语法格式:if condition then command1 fi末尾的fi就是if倒过来. 写成一行: if condition; then comma ...
- Hyperscan与Snort的集成方案
概况 Hyperscan作为一款高性能的正则表达式匹配库,非常适用于部署在诸如DPI/IPS/IDS/NGFW等网络解决方案中.Snort (https://www.snort.org) 是目前应用最 ...
- ASC与HEX之间的转换
ASC与HEX之间的转换 有这么两个函数: 函数 原型 功能 返回值 参数 备注 hex2asc __int16 hex2asc(unsigned char *strhex,unsigned char ...
- 格式化输出之 每行N个元素 list拆分
for i in range(0,len(XSECT),5): out_BLDdat.write(' '.join( map('{:10.4f}'.format,XSECT[i:i+5]) ) + ' ...
- kdump 调试手段
kdump是在系统崩溃的时候用来转储内存运行参数的一个工具和服务,打个比方,如果系统一旦崩溃那么正常的内核就没有办法工作了,在这个时候将由kdump产生一个用于capture当前运行信息的内核,该内核 ...
- Python之路番外(第二篇):PYTHON基本数据类型和小知识点
一.基础小知识点 1.如果一行代码过长,可以用续行符 \换行书写 例子 if (signal == "red") and \ (car == "moving") ...
- php emoji mysql保存和搜索
MySQL版本>=5.5.3 表字符集: utf8mb4 解决保存 排序规格: utf8mb4_bin 解决搜索 PHP: set names utf8mb4 操作系统: WIN10 MAC