Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing JSON files from NLog #25

Closed
ZeroAviation opened this issue Nov 27, 2023 · 4 comments
Closed

Parsing JSON files from NLog #25

ZeroAviation opened this issue Nov 27, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ZeroAviation
Copy link

Hi,

I want to parse JSON files from an application which uses nlog. I can specify the layout in any manner.

The question is, is using "Log line patterns" and regex the only option? or can I directly access the json schema?

Thanks in advance!

@ZeroAviation
Copy link
Author

Here is an example file

example.json

@hamster620
Copy link
Collaborator

@ZeroAviation Yes, currently using Log line patterns is the only way to parse raw logs including JSON files.

If the file contains valid JSON format data, you can let ULogViewer format the raw JSON data by enabling Format JSON data when reading:
截圖 2023-11-28 清晨7 59 31

Then you will get formatted JSON data:
截圖 2023-11-28 上午8 02 12

Because JSON properties will be separated into multiple lines, it is easier to define Log line patterns with multiple patterns which is more flexible to add/remove patterns in the future. You can also set Way of matching log lines with patterns to Arbitrary order to ignore the order of JSON properties:
截圖 2023-11-28 上午8 05 05

But in your case the JSON file contains incomplete JSON data, ULogViewer cannot parse it correctly. We will try adding ability to parse incomplete JSON data in the next version.

@hamster620 hamster620 added the enhancement New feature or request label Nov 28, 2023
@ZeroAviation
Copy link
Author

Hi @hamster620

Thank you for your reply! This is the default output when you select JsonLayout in NLOG.

I will explore alternative options.

Thanks again,
Matt

@hamster620 hamster620 self-assigned this Dec 1, 2023
@hamster620 hamster620 added this to the 4.0 milestone Dec 9, 2023
@hamster620
Copy link
Collaborator

Now JSON data with multiple root elements can be formatted in 4.0.1.1222.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants