log4net RemotingAppender 的配置
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 的配置的更多相关文章
- 关于log4net日志的配置流程
最近又重新整理一下log4net日志的配置,现在记录一下流程和一些遇到的问题,以备后续使用,具体的配置参数等信息.此文无,见谅! 1. 下载log4net.dll文件(网上很多,随便找一个!) 2. ...
- Log4Net 的简要配置
引用log4net.dll AssemblyInfo.cs中 [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyF ...
- C# 日志输出工具库—log4net 安装、配置及简单应用
1.下载和安装 注意每次安装只是安装到本项目中,换了另一个项目需要再次安装和配置. 我使用的是Visual Studio 2013 社区版,在tools中找到NuGet包管理. 搜索log4net并点 ...
- log4net独立配置文件配置(winfrom)
log4net配置很多,具体配置步骤不细说,具体说出个人遇到的问题. 在winfrom和web应用程序中配置,在默认配置文件配置都没问题,因为EF也写在默认配置文件中,就会冲突解决办法就是将log4. ...
- log4net架构、配置、使用
架构说明 架构说明 上图是官方文档的提供的代码组织. Log4net的核心组件有: Logger, Appender, Filter, Layout, Object Render, Logger介绍 ...
- log4net的基本配置及用法
[1].[代码] [C#]代码 跳至 [1] [2] ? 1 2 using System.Reflection; //使用反射 static private ILog log = log4net. ...
- Log4net日志GUI配置工具
关于log4net的配置文章在园子里真的很多,但是有关GUI界面配置的文章确定太少,改写了一个以前很早的工具 以前的那个有很多的问题,这个基本的大的问题没有,可能一个小问题还是需要修改下,基本功能肯定 ...
- Log4net配置文件一般配置
配置文件一般配置 <?xml version="1.0"?> <configuration> <configSections> <sect ...
- log4net 使用与配置 每天一份log文件
1.下载 或 在nuget安装 log4net 2. web.config (app.config) <configuration> <configSections> < ...
随机推荐
- dev TreeList拖拽
一.说明 使用dev控件,TreeList1向TreeList2拖拽 二.属性 //允许拖拽 treeList1.AllowDrop = true; tre ...
- [C#] Control.Invoke方法和跨线程访问控件(转载)
转载前,在网上找了好多INVOKE方法的文章,就这个看着还可以,明白了大概,以后再深用的时候再研究 ,废话少说上转载(连转载都说的这么有气势,哈哈) 在设计界面时,我们经常需要将一些需要时间才能完 ...
- JavaScript 中 map、foreach、reduce 间的区别
一直对map.foreach.reduce这些函数很是生疏,今天看underscorejs时好好研究了一下,一研究我就更懵了,这不是一样嘛,都是遍历,所以我就去知乎找了一下,整理出了比较好的几个说法. ...
- File相关的读取和写入以及复制
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileI ...
- 每天一点Android干货-Activity的生命周期
Activity Activity是这样一个程序组件,它为用户提供一个用于任务交互的画面. 一个应用程序通常由多个activity组成,它们彼此保持弱的绑定状态.典型的,当一个activity在一个应 ...
- mac攻略(六) -- mac根目录分析
根目录截图如下 符合unix传统的目录 /bin 传统unix命令的存放目录,如ls,rm,mv等. /sbin 传统unix管理类命令存放目录,如fdisk,ifconfig等等. /usr ...
- Eclipse+maven+scala2.11.8+spark2.0.0的环境部署
主要在maven-for-scalaIDE纠结了,因为在eclipse版本是luna4.x 里面有自己带有的maven. 根据网上面无脑的下一步下一步,出现了错误,在此讲解各个插件的用途,以此新人看见 ...
- 关于工程结合git的配置
我们通常把代码放到git sever中,(scm manager)中,上传,下载代码, 可是通常工程的代码改动会有图标提示,改动过的,或者新增的,那么需要在eclipse的工程中做一下简单配置 1,工 ...
- 关于C语言宏定义 使用do{ xxxx }while()
暂时感觉像是由于":"的原因,关于使用习惯方面的问题!! 下面是copy的: 这样的宏见过么: Cpp代码 #define FOO(x) do {\ some_code_line_ ...
- Spark学习(四) -- Spark作业提交
标签(空格分隔): Spark 作业提交 先回顾一下WordCount的过程: sc.textFile("README.rd").flatMap(line => line.s ...