NLog multiline Log Message

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NLog multiline Log Message

Arjan
Hello,

I am having an issue with how to display my log messages correctly. I use NLog to log, and I log a memory dump. But for some reason I only see the first line of the message and not all the remaining lines (which are a lot).

So my pattern: ${threadid} ${longdate} ${uppercase:${level}}: ${message}

LogExample:

10 2016-09-27 11:11:31.5372 DEBUG: {Something.Something.Something}
  Type: AType
  VendorId: 0
  ProductId: 0
  IsSpoofDetectionSupported: True
  SpoofDetection: False
  Owner: { }


In Log4Viewer I only see: {Something.Something.Something}

Anyone got any types how I can see the rest of the message?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: NLog multiline Log Message

Philipp Lauchner
Administrator
Dear Arjan,

we could recreate your problem. There seems to be a bug when the date has a precessor (thread id in your case) when reading multiline messages.
Thank you for reporting this issue, we will try to find a solution.

Yours sincerely

Philipp Lauchner
PROSA GmbH  
Development & Support
Reply | Threaded
Open this post in threaded view
|

Re: NLog multiline Log Message

Arjan
Hi Philipp,

Any update about this issue?

Kind regards,

Arjan
Reply | Threaded
Open this post in threaded view
|

Re: NLog multiline Log Message

Philipp Lauchner
Administrator
Dear Arjan,

we further investigated your issue. It seems like this behaivor is not that much of a bug in the parsing of messages, but caused by the ambigous nature of pattern formated messages.
In pattern formated messages every line represents a message, as long as they are not not explicitly specified to span accross multiple lines, e.g. with the pattern ${longdate} ${newline} ${message}. In this case a message always consists of one line of date and one line of message.

Yet in your case the line breaks happen within a field, which can not be specified in the layout. Also this could not be definined without further problems regarding ambiguity: What will happen to messages, that do not log multiple lines etc?
If the messages start with a date and Log4View cannot parse the start of a line into a valid DateTime, the current line will be treated as faulty and attatched to the previous line. This is why multiline messages work just fine when they start with their time.

You could replace the line breaks within your messages by using the following Layout renderer:
https://github.com/NLog/NLog/wiki/Replace-NewLines-Layout-Renderer

Alternatively we just released a new beta version with a workaround included. With this version you can define new messages by letting them start with a prefix. This prefix will work even when messages span over multiple lines.
For example if you add a | to the start of every message you can use the following pattern:
| ${threadid} ${longdate} ${uppercase:${level}}: ${message}

The messages have to look like this in your logfile:
| 10 2016-09-27 11:11:31.5372 DEBUG: {Something.Something.Something}
  Type: AType
  VendorId: 0
  ProductId: 0
  IsSpoofDetectionSupported: True
  SpoofDetection: False
  Owner: { }


Yours sincerely

Philipp Lauchner
PROSA GmbH  
Development & Support