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
|
<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的更多相关文章
- 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 ...
随机推荐
- Win7 64位VC6调试无法退出
错误信息:LINK: fatal error LNK1168: cannot open Debug/test1.exe for writing 根据网络上查询,找到最终原因,DM.dll,TLLOC. ...
- ubuntu 无法挂载U盘
问题描述: usb 1-1: device descriptor read/64,error 18usb 1-1: device descriptor read/64,error 18usb 1-1: ...
- python multiprocessing 和tcp
#用类方法 服务端 from socket import *from multiprocessing import Processimport os class Myprocess(Process): ...
- js原生语法实现表格操作
HTML页面: <!doctype html> <html lang="en"> <head> <meta charset="U ...
- Oracle性能优化2- 依据场景选择技术
1.索引的坏处 索引可以加快查询效率,但是使用不当,会造成插入性能很低 drop table test1 purge; drop table test2 purge; drop table test3 ...
- 18.Mysql SQL优化
18.SQL优化18.1 优化SQL语句的一般步骤 18.1.1 通过show status命令了解各种SQL的执行频率show [session|global] status; -- 查看服务器状态 ...
- Redis单机安装
安装过程 安装环境 ubuntu14.04 server wget http://download.redis.io/releases/redis-3.2.5.tar.gz tar -xzvf ./r ...
- 789A Anastasia and pebbles
A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...
- day 3:注释,缩进
本节内容: 1,注释 2,缩进 1,注释: 使用#可以注释单行 # print("hello world") 三个双引号也可以注释多行 """ pri ...
- PS合成的5个要点:场景、对比、氛围、模糊、纹理
是否觉得做合成打开PS之后无处下手,做完之后总觉得缺少故事情节?这一次分享的5个要点,是个人觉得需要重视的,每一点都有一个案例来让作品变得多一份惊喜.(申明:文中素材均来自网络,这里仅作分享交流作用) ...