简体   繁体   中英

Is there a low level TCP appender for log4net?

I've been using the UDPAppender to send logs to logstash . I would like to be able to achieve failover of the logstash server through DNS.

Implicitly, the UDPAppender does not detect whether or not the remote UDP port is available, but even if it did, when I configure it with a DNS name for remoteAddress , it is resolved to the ip address during initialization and recorded as an ip address in the RemoteAddresss property. I am aware of the RemotingAppender , but this doesn't seem to like logstash because the logstash TCP input isn't implementing the .NET remoting protocol, and it looks as though it will suffer the same problem of resolving the remote ip address through DNS at the initialization step only.

I'm considering implementing my own appender, by either wrapping the UDPAppender with a ping or copying the RemotingAppender by handling reconnection through the DNS name. Does anything like this already exist?

Have you tried log4stash ?.
It's a log4net appender which have few similar features like logstash and sends your logs right into Elasticsearch.
That way you will have one less "failure point" in the way to elasticsearch (no need to use logstash at all).

And if you want to stick to TCPAppender,
You can transfer the code of UDPAppender into a tcp without too much effort.
I did it once but unfortunately I can't publish the code.

I found this here , the UdpAppender is near the end

SDK reference

UdpAppender

For full details see the SDK Reference entry: log4net.Appender.UdpAppender.

The following example shows how to configure the UdpAppender to send events to a RemoteAddress on the specified RemotePort.

<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
    <localPort value="8080" />
    <remoteAddress value="224.0.0.1" />
    <remotePort value="8080" />
    <layout type="log4net.Layout.PatternLayout, log4net">
        <conversionPattern value="%-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM