Multiline from log4net truncating

(Matthew Good) #1

We are using log4net to ship logs from one of our applications to graylog. When log4net ships a multiline file to graylog it’s getting truncated at the line break. What can I do to fix this?

(Jochen) #2

What’s log4net?
What’s the configuration of your log4net appenders?
Which protocol are you using to ship logs to Graylog?
What type of input have you created in Graylog?
What’s the configuration of the Graylog input receiving these messages?

(Matthew Good) #3

Log4net is a log shipper 4 dotNet.

<layout type="log4net.Layout.PatternLayout" value="%d | %property{Site} | %-5p | %c | %m |" />

It ships logs to graylog via syslog format over udp port.

allow_override_date: true
expand_structured_data: true
force_rdns: false
override_source: Elevate Local Testing
port: 51980
recv_buffer_size: 262144
store_full_message: true

The error on the message that fails:

For rule 'Elevate Service Rewrite': In call to function 'to_string' at 16:21 an exception was thrown: null

The pipleline rule:

rule "Elevate Service Rewrite"
    contains(to_string($message.source),"Elevate Local Testing",true)
    let splt_msg = split("\\Q|\\E",to_string($message.message));
    let splt_src = split(" ",to_string(splt_msg[0]));
    let splt_time = split(",",to_string(splt_src[2]));
    let timestmp = concat(to_string(splt_src[1]),"T");
    let timestmp = concat(to_string(timestmp),to_string(splt_time[0]));
    let timestmp = concat(to_string(timestmp),".");
    let timestmp = concat(to_string(timestmp),to_string(splt_time[1]));
    let timestmp = concat(to_string(timestmp),"Z");

From what I can tell log4net is shipping the messages with windows style line breaks.

(Jochen) #4

Syslog is a line-based protocol, so of course the message ends with the line break (no matter if LF or CRLF).

The error message is correct because there is no second match (splt_msg[1]). The message simply ends after the first line break.

If you want to use multi-line messages, consider deploying one of the GELF appenders for Log4Net from the Graylog Marketplace:

(system) #5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.