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. C&Cpp.CallGraph

    1. CodeViz http://www.skynet.ie/~mel/projects/codeviz/ 2. http://my.oschina.net/zmlblog/blog/186308

  2. php中static静态关键字的使用方法和应用场景

    php中除了常规类和方法的使用,访问控制之外,还有静态关键字static,静态变量可以是局部变量也可以是全局变量,当一个程序段执行完毕时,静态变量并没有消失,它依然存在于内存中,下次在定义时还是以前的 ...

  3. 离线在MVC4中的使用

    最近在项目中用到了离线功能,自己感觉挺高端的,但是遇到了一些问题. 现在工作告一小段落,就把这次离线工作中遇到的关键技术点和难题记录下来. 什么是离线,什么时候需要离线 离线:Offline,不联网也 ...

  4. readv writev示例程序

    当 readv() 时候,需要程序自己提供space,接收数据. #include <stdio.h> #include <stdlib.h> #include <str ...

  5. String类为什么设计成不可变的

    在Java中将String设计成不可变的是综合考虑到各种因素的结果,需要综合考虑内存.同步.数据结构以安全方面的考虑. String被设计成不可变的主要目的是为了安全和高效. 1)字符串常量池的需要 ...

  6. How to return AJAX errors from Laravel Controller?

    Questions: I am building a REST API with Laravel 5. In Laravel 5, you can subclassApp\Http\Requests\ ...

  7. java 23种设计模式学习。

    一.3大类设计模式:创建型,结构型,行为型. a.5种创建型模式:工厂方法,抽象工厂,单例,建造者,原型. b.7种结构型模式:适配器,装饰器,代理,外观,桥接,组合,享元. c.11种行为型模式:策 ...

  8. 关键词提取_tf_idf

    TF-IDF(term frequency-inverse document frequency)-词频-逆文档频率 TF:统计一个词在文档中出现的频次,次数越多,表达能力越强 IDF:统计一个词在文 ...

  9. 设计师别浪费时间啦,快来试试这款Sketch标注插件吧

    随着移动互联网的快速发展,用户的需求也在不断地增大,这对产品经理还有设计师的考验是越来越大.市场环境的变化让我们深信为快不破,但是一个产品的产出需要各个环节的紧密配合,但往往在产品输出过程中,由于分工 ...

  10. (转)用webbrowser做的网站登陆程序,如何获取cookie并且保存在程序中 (IE8有效) ,用途嘛,你懂的。

    今天帮朋友做了个工具,用webbrowser做的,用户使用用户名密码登陆网站后,需要在后台下载和分析一些页面. 分析页面使用的是htmlparser .net版 里面唯一需要解决的问题是,登陆后的co ...