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. RollingFileAppendercompletely 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.

原于这段话, 大致的是文件方式写日志,会遇到多个process同时写入同一个日志文件的问题.最后提到最好的方法是使用RemotingAppender。 之后花了一点时间研究了一下。主要想讲几个注意点。客户端的配置

<appender name="RemotingAppender" type="log4net.Appender.RemotingAppender" >
<sink value="tcp://localhost:8085/LoggingSink" />
<lossy value="false" />
<bufferSize value="95" />
<onlyFixPartialEventData value="true" />
</appender>
注意:bufferSize 是表示一个缓存区大小,remotingappender不是立即就把日志发送给服务端的,等到缓冲区满了设置的大小之后才会发,如果想立即发送请把这个值设成0
当然remotingappender 和其他的appender一样都可以设置日志格式的。
主要是讲一下 服务端
首先注册信道, 客户端配置了tcp 所以服务器端也使用TcpChannel 注册的时候  ChannelServices.RegisterChannel(channel, false); 注意第二个参数要是设置成false;
(我就在这里花了很多时间)。
注册远程对象 使用  RemotingServices.Marshal (注log4net 内部使用的是接口方式激活远程对象)
远程对象必须继承 RemotingAppender.IRemoteLoggingSink借口
第二种发布方式,使用log4net 提供的 RemoteLoggingServerPlugin 插件
log4net.LogManager.GetRepository().PluginMap.Add(new log4net.Plugin.RemoteLoggingServerPlugin("LoggingSink"))
其中“LoggingSink”是远程对象发布的名称
使用第二种方式,不需要自己实现远程对象,log4net中帮我们实现好了一个远程对象。要获取日志信息,只要在服务器端在配置一个appender 就可以了!

log4net RemotingAppender 的配置的更多相关文章

  1. 关于log4net日志的配置流程

    最近又重新整理一下log4net日志的配置,现在记录一下流程和一些遇到的问题,以备后续使用,具体的配置参数等信息.此文无,见谅! 1. 下载log4net.dll文件(网上很多,随便找一个!) 2. ...

  2. Log4Net 的简要配置

    引用log4net.dll AssemblyInfo.cs中 [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyF ...

  3. C# 日志输出工具库—log4net 安装、配置及简单应用

    1.下载和安装 注意每次安装只是安装到本项目中,换了另一个项目需要再次安装和配置. 我使用的是Visual Studio 2013 社区版,在tools中找到NuGet包管理. 搜索log4net并点 ...

  4. log4net独立配置文件配置(winfrom)

    log4net配置很多,具体配置步骤不细说,具体说出个人遇到的问题. 在winfrom和web应用程序中配置,在默认配置文件配置都没问题,因为EF也写在默认配置文件中,就会冲突解决办法就是将log4. ...

  5. log4net架构、配置、使用

    架构说明 架构说明 上图是官方文档的提供的代码组织. Log4net的核心组件有: Logger, Appender, Filter, Layout, Object Render, Logger介绍 ...

  6. log4net的基本配置及用法

    [1].[代码] [C#]代码 跳至 [1] [2] ? 1 2 using System.Reflection;  //使用反射 static private ILog log = log4net. ...

  7. Log4net日志GUI配置工具

    关于log4net的配置文章在园子里真的很多,但是有关GUI界面配置的文章确定太少,改写了一个以前很早的工具 以前的那个有很多的问题,这个基本的大的问题没有,可能一个小问题还是需要修改下,基本功能肯定 ...

  8. Log4net配置文件一般配置

    配置文件一般配置 <?xml version="1.0"?> <configuration> <configSections> <sect ...

  9. log4net 使用与配置 每天一份log文件

    1.下载 或 在nuget安装 log4net 2. web.config (app.config) <configuration> <configSections> < ...

随机推荐

  1. javascript: parse JSON

    $.get("/intra/do/sequence_has_codonList.pl",function(data){ data = JSON.parse(data); // ar ...

  2. Newtonsoft.Json

    在线生成实体:http://tool.chinaz.com/tools/json2entity.aspx RootObject ac = new RootObject(); ac = JsonConv ...

  3. Node包管理工具

    Node包管理工具 只是简单的介绍一些工具的使用,有利于开发过程.除了介绍Node包管理工具,还介绍了前端打包工具,前端模块管理工具 Node包管理工具:    --npm    --cnpm    ...

  4. ansible非root用户批量修改root密码

    前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...

  5. EF 如何更新少量字段

    EF更新少量字段需要解决两个问题 1.动态的将需要更新的字段提取出来 2.将提取出来的字段设为更新状态 通常更新的时候,都是根据条件将实体取出来,然后赋值字段,最后更新整个实体,所以在方法上看似是更新 ...

  6. Python爬网获取全国各地律师电话号

    [本文出自天外归云的博客园] 从64365网站获取全国各地律师电话号,用到了python的lxml库进行对html页面内容的解析,对于xpath的获取和正确性校验,需要在火狐浏览器安装firebug和 ...

  7. Windows 版本的iTunes 修改iPhone的备份路径

    帮朋友解决修改iPhone的备份路径问题,故写篇博客整理记录一下. 所需工具 Junction工具 下载该工具然后将文件放到C:\Windows 目录下,如下图: 找到iTunes的备份路径 Wind ...

  8. 一首诗,致亲爱的csdn

    来自csdn的Rachel-Zhang姐姐 还记得--致亲爱的csdn 还记得你年轻时的摸样? 简单的文字,无瑕的脸庞. 现在的你,满脸风霜. 五粮液的广告,在我的文章中久久荡漾. 还记得当初的梦想? ...

  9. 【前端】在Gulp中使用Babel

    Install $ npm install --save-dev gulp-babel babel-preset-es2015 用法1: const gulp = require('gulp'); c ...

  10. 微信小程序-登陆、支付、模板消息

    wx.login(OBJECT) 调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key).用户数据的加解密通讯需要 ...