LogViewPlus Support

Custom Parser and Messages with Multiple Lines

https://www.logviewplus.com/forum/Topic814.aspx

By AndreasP - 4 Nov 2020

Hi Toby,

I am trying to write a custom parser for our log files since the default parser has some problems with special cases.
I have a first version of the custom parser, however I have problems correctly parsing log entries with multiple Lines.

Simplified Example:
2020.01.01 Test 1
2020.01.02 Test 2.1
Test 2.2
Test 2.3
2020.01.03 Test 4


From what I understand from the documentation the IsLogEnty method should return true when I detect a new log entry. In the above example this would be detecting if the lines start with a date, and in this case return true, otherwise false.

In the Parse method then I parse the given logentry line and fill the LogEntry class.

When I run the custom parser it basically works, however in the log entry grid for the second entry I only see the line "Test 2.1" and not the lines "Test 2.2" and "Test 2.3". I can see them in the original entry view, but I would also like to see them in the log entry grid.

In contrast when I use the Pattern Parser then the log entry grid shows all three lines. How can I achieve this with the custom parser?

Regards
Andreas
By LogViewPlus Support - 4 Nov 2020

Hi Andreas,

This is an excellent question and something that I can see is missing from our documentation. 

You will need to implement the "IFinalizeLogEntry" interface.  Your implementation will be something like:

/// <summary>
/// Implementing IFinalizeLogEntry will give us a chance to process any unparsed data. Unparsed data will
/// automatically be added to the OriginalLogEntry, but you may want to process it further. Unparsed data
/// will be a collection of all lines where "IsLogEntry" returned false.
///
/// Here, we are adding the unprocessed data to the message for display in the LogViewPlus grid view.
/// </summary>
/// <param name="entry">The log entry to be finalized.</param>
/// <param name="unparsedData">Any data that could not be parsed.</param>
/// <param name="result">The result of the log parse.</param>
public void FinalizeLogEntry(LogEntry entry, string unparsedData, ParseResult result)
{
  if (string.IsNullOrEmpty(unparsedData))
   return;

  entry.Message += unparsedData;
}


I will put this in the sample code and update the documentation.  Thanks for bringing this to our attention!

Toby
By AndreasP - 4 Nov 2020

Hi Toby,

works perfect. Thanks!

Andreas
By LogViewPlus Support - 4 Nov 2020

Glad to hear that is working for you Andreas.  Please let me know if you have any further questions or issues.

Toby