lockingModel in log4net 日志文件不能被其他进程写入
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"/>
就可以确保其他进程可以操作文件
但是不足之处是,会有性能问题
lockingModel in log4net 日志文件不能被其他进程写入的更多相关文章
- Log4net日志文件自动按月份存放和日志独占问题的解决
让log4net日志文件自动按月份存放 log4net日志文件的作用还真不小,可以保存管理员.用户对数据库的任何操作,保存管理员和用户的登录记录,分析系统运行错误,所以不舍得随便将日志文件Delete ...
- log4net日志文件的应用
日志作为快速定位程序问题的主要手段,日志几乎是所有程序都必须拥有的一部分,下面我们就看下怎么使用log4net.dll文件: 1.下载log4net.dll文件 2.创建自己的项目 3.在自己项目下的 ...
- .NET CORE 控制台应用程序配置log4net日志文件
使用文件格式记录日志 1.新建一个.NET CORE控制台应用程序,添加log4net.dll引用,打开工具->NuGet包管理器->管理解决方案的NuGet程序包. 2.在NuGet-解 ...
- 如何让Log4net日志文件按每月归成一个文件夹,StaticLogFileName参数的用法
想要让Log4net日志(以下称日志)按每月自动归类为一个文件夹,为此,学习和修改了log4net.config文件.查了资料,重点是以下这些参数: <param name=" ...
- C#中添加log4net(日志文件)
1.先下载引用“log4net” 2.然后再App.config配置 3.添加一个LogHandler类 4.在Assemblyinfo类中添加配置的读取文件 5.运用日志文件 6.显示结果
- 动态指定log4net日志文件名称
如果是希望日志文件按常见的日期格式动态命名,没什么好说的,直接修改app.config <param name="DatePattern" value="yyyyM ...
- log4net 日志文件占用,不能及时释放
在appender 下面加 <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
- Log4Net 日志文件分类保存
1.app.config <configSections> <section name="log4net" type="log4net.Config.L ...
- 解决log4net多进程日志文件被占用
<log4net debug="true"> <appender name="RollingLogFileAppender" type=&qu ...
随机推荐
- Linux命令之split
split用来将大文件分割成小文件.有时文件越来越大,传送这些文件时,首先将其分割可能更容易. 使用vi或其他工具诸如sort时,如果文件对于工作缓冲区太大,也会存在一些问题. 因此有时没有选择余地, ...
- 第四篇:了解 C++ 默默编写并调用的函数
前言 对于一个类来说,最最基础的三类成员函数莫过于:构造函数,析构函数以及拷贝函数 (copy构造函数和=重载函数).即使你的类没有为这些函数做出定义,C++ 也会自动为你创建.本文将讲述的是 C++ ...
- 【BZOJ3444】最后的晚餐 乱搞
[BZOJ3444]最后的晚餐 Description [问题背景] 高三的学长们就要离开学校,各奔东西了.某班n人在举行最后的离别晚餐时,饭店老板觉得十分纠结.因为有m名学生偷偷找他,要求和自己暗恋 ...
- Velocity模板引擎介绍
整理下Velocity使用方法,整理比较详细用例 1 Velocity基础语法 1.1 用户和开发人员参考文档 http://velocity.apache.org/engine/releases/v ...
- JavaWeb 之过滤器
1. 什么是过滤器 Servlet 是用来处理请求的, 过滤器是用来拦截请求的. 当用户请求某个 Servlet 时,会先执行部署在这个请求上的 Filter, 而 Filter 决定是否调用 Ser ...
- HTML代码的美感
每当我访问精美的网站,我都情不自禁地会去查看源代码.这就好比你拥有一副X光眼镜,能够看到任何人--甚至透视他们的遮羞布.这简直是天经地义的事情嘛!我迫不及待地想了解,这个精美的网站,是不是由同样具有美 ...
- Python 中星号作用:解包&打散
python中’*’和’**’的使用分两个方面,一个是计算,另一个是参数传递过程中元素的打包和解包. 计算方面 ‘*’和’**’在python中最常见的作用分别是‘相乘’和‘乘幂’,如下: > ...
- spring mvc 关键接口 HandlerMapping HandlerAdapter
HandlerMapping Spring mvc 使用HandlerMapping来找到并保存url请求和处理函数间的mapping关系. 以DefaultAnnotationHandlerMa ...
- 1.6 使用电脑测试MC20的读取带中文短信功能
需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...
- 通过ip得到所在城市,以及城市所在经纬度坐标(监控系统中用的该代码,小航哥)
监控系统中就是利用的该段代码,实现通过ip得到所在城市,以及城市所在经纬度坐标,最后得以利用echarts实现模拟迁移的效果 api官方介绍: http://lbsyun.baidu.com/inde ...