log4net RemotingAppender
RemotingAppender
For full details see the SDK Reference entry: log4net.Appender.RemotingAppender.
The following example shows how to configure the RemotingAppender to deliver logging events to a specified Sink (in this example the sink is tcp://localhost:8085/LoggingSink). In this example the events are delivered in blocks of 95 events because of the BufferSize. No events are discarded. The OnlyFixPartialEventData option allows the appender to ignore certain logging event properties that can be very slow to generate (e.g. the calling location information).
- <appender name="RemotingAppender" type="log4net.Appender.RemotingAppender" >
- <sink value="tcp://localhost:8085/LoggingSink" />
- <lossy value="false" />
- <bufferSize value="95" />
- <onlyFixPartialEventData value="true" />
- </appender>
This example configures the RemotingAppender to deliver the events only when an event with level ERROR or above is logged. When the events are delivered, up to 200 (BufferSize) previous events (regardless of level) will be delivered to provide context. Events not delivered will be discarded.
- <appender name="RemotingAppender" type="log4net.Appender.RemotingAppender" >
- <sink value="tcp://localhost:8085/LoggingSink" />
- <lossy value="true" />
- <bufferSize value="200" />
- <onlyFixPartialEventData value="true" />
- <evaluator type="log4net.Core.LevelEvaluator">
- <threshold value="ERROR"/>
- </evaluator>
- </appender>
RemotingAppender Class
This Appender is designed to deliver events to a remote sink. That is any object that implements the RemotingAppender. IRemoteLoggingSink interface. It delivers the events using .NET remoting. The object to deliver events to is specified by setting the appenders Sink property.
The RemotingAppender buffers events before sending them. This allows it to make more efficient use of the remoting infrastructure.
Once the buffer is full the events are still not sent immediately. They are scheduled to be sent using a pool thread. The effect is that the send occurs asynchronously. This is very important for a number of non obvious reasons. The remoting infrastructure will flow thread local variables (stored in the CallContext), if they are marked as ILogicalThreadAffinative, across the remoting boundary. If the server is not contactable then the remoting infrastructure will clear the ILogicalThreadAffinative objects from the CallContext. To prevent a logging failure from having side effects on the calling application the remoting call must be made from a separate thread to the one used by the application. A ThreadPool thread is used for this. If no ThreadPool thread is available then the events will block in the thread pool manager until a thread is available.
Because the events are sent asynchronously using pool threads it is possible to close this appender before all the queued events have been sent. When closing the appender attempts to wait until all the queued events have been sent, but this will timeout after 30 seconds regardless.
If this appender is being closed because the ProcessExit event has fired it may not be possible to send all the queued events. During process exit the runtime limits the time that a ProcessExit event handler is allowed to run for. If the runtime terminates the threads before the queued events have been sent then they will be lost. To ensure that all events are sent the appender must be closed before the application exits. See Shutdown() for details on how to shutdown log4net programmatically.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-07-02 jQuery file upload callback options
2019-07-02 jQuery file upload process queue
2019-07-02 How do I add a simple onClick event handler to a canvas element?
2019-07-02 JavaScript 事件不触发
2019-07-02 jquery.fileupload-image-editor.js 中actions.resizeImage
2019-07-02 What's the difference between HEAD^ and HEAD~ in Git?
2017-07-02 Create the Project