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

lockingModel in log4net 日志文件不能被其他进程写入的更多相关文章

  1. Log4net日志文件自动按月份存放和日志独占问题的解决

    让log4net日志文件自动按月份存放 log4net日志文件的作用还真不小,可以保存管理员.用户对数据库的任何操作,保存管理员和用户的登录记录,分析系统运行错误,所以不舍得随便将日志文件Delete ...

  2. log4net日志文件的应用

    日志作为快速定位程序问题的主要手段,日志几乎是所有程序都必须拥有的一部分,下面我们就看下怎么使用log4net.dll文件: 1.下载log4net.dll文件 2.创建自己的项目 3.在自己项目下的 ...

  3. .NET CORE 控制台应用程序配置log4net日志文件

    使用文件格式记录日志 1.新建一个.NET CORE控制台应用程序,添加log4net.dll引用,打开工具->NuGet包管理器->管理解决方案的NuGet程序包. 2.在NuGet-解 ...

  4. 如何让Log4net日志文件按每月归成一个文件夹,StaticLogFileName参数的用法

    想要让Log4net日志(以下称日志)按每月自动归类为一个文件夹,为此,学习和修改了log4net.config文件.查了资料,重点是以下这些参数:      <param name=" ...

  5. C#中添加log4net(日志文件)

    1.先下载引用“log4net” 2.然后再App.config配置 3.添加一个LogHandler类 4.在Assemblyinfo类中添加配置的读取文件 5.运用日志文件 6.显示结果

  6. 动态指定log4net日志文件名称

    如果是希望日志文件按常见的日期格式动态命名,没什么好说的,直接修改app.config <param name="DatePattern" value="yyyyM ...

  7. log4net 日志文件占用,不能及时释放

    在appender 下面加 <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

  8. Log4Net 日志文件分类保存

    1.app.config <configSections> <section name="log4net" type="log4net.Config.L ...

  9. 解决log4net多进程日志文件被占用

    <log4net debug="true"> <appender name="RollingLogFileAppender" type=&qu ...

随机推荐

  1. C字符串复制

    void mystrcpy(char *from, char *to) { for(; *from != '\0'; from++, to++) { *to = *from; } *to = '\0' ...

  2. lumen 单元测试

    laravel学院:http://laravelacademy.org/post/238.html 简书:https://www.jianshu.com/p/d8b3ac2c4623 问题解决:htt ...

  3. IDEA : Git Pull Failed 解决(IDEA中使用stash功能)

    一.问题: 本地要commit代码,commit之前需pull代码,但pull提示冲突.如下 Git Pull Failed Your local changes would be overwritt ...

  4. FZU 2099 魔法阵(计算几何)

     Problem 2099 魔法阵 Accept: 120    Submit: 289 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  5. TFS二次开发-基线文件管理器(2)-TFS登录

    首先需要做一个TFS的登录. 以前的文章是使用的DomainProjectPicker 最新的VS里面使用的是TeamProjectPicker 首先可以在WinForm程序上写一个Button,然后 ...

  6. Quality of service

    w https://en.wikipedia.org/wiki/Quality_of_service Quality of service (QoS) is the overall performan ...

  7. python系列十二:python3模块

    #!/usr/bin/python # This Python file uses the following encoding: gbk #Python3 模块 '''用 python 解释器来编程 ...

  8. Win7环境下Apache+mod_wsgi本地部署Django

    django基础已经掌握的同学可以尝试将项目发布已寻找些许成就感,以鼓励自己接下来进行django的进阶学习 以前你总是使用python manage.py runserver进行服务启动,但是却不知 ...

  9. 理解是最好的记忆方法 之 CSS中a链接的4个伪类为何有顺序

    在CSS中,a标签有4种伪类,分别为: a:link, a:visited, a:hover, a:active 对其稍有了解的前端er都知道,4个伪类是有固定顺序的(LVHA),否则很容易出现预期之 ...

  10. app开发学习需要经历哪些流程

    app开发学习需要经历哪些流程?如何零基础入门app开发?以下是知乎热心开发者的经验总结,对学习app开发有很好的参考意义   1.如果没有编程基础的,学习基础知识的过程肯定是必须的.2.有了一些基础 ...