Support for Nlog using log4J format

Notes, tips, and other usefull things on how to use LogMX

Moderator: admin

Post Reply
Posts: 2
Joined: Thu Sep 21, 2017 7:48 pm

Support for Nlog using log4J format

Post by mbalsam » Thu Sep 21, 2017 7:58 pm

I want to use LogMx with file logs generated by Nlog.

Nlog has a layout formatter that they call Log4JXmlEventLayout

When i generate the log file using the File target with this option, its not recognized.

One line from this file looks like this

<log4j:event logger="xxx" level="INFO" timestamp="1506010090073" thread="1"><log4j:message>the messages</log4j:message><log4j:properties><log4j:data name="log4japp" value="xxxxxxxxxx" /><log4j:data name="log4jmachinename" value="DESKTOP-RSKK47D" /></log4j:properties></log4j:event>

Any Tips?

Site Admin
Posts: 523
Joined: Sun Dec 17, 2006 10:30 pm

Re: Support for Nlog using log4J format

Post by admin » Fri Sep 22, 2017 12:11 am


For now, LogMX doesn't come with a NLog Parser (and as you can see here, this NLog format seems different from Log4jXMLLayout), so you can create a LogParser in LogMX in order to parse this new format: you can go to menu "File" > item "Configure Log Parsers...", and click on the green "+" button at the right to create a Parser. In your case, you could use the 4 types of Parser for what you want to achieve:
  1. "SimpleParser" but only in Pro version
  2. "Log4jPatternParser" which is the one I'm using in this post
  3. "RegexParser" a bit too complicated for your needs
  4. "JavaClassParser" which is overkill for this log format

So using a "Log4jPatternParser" (you can use this Parser even if it's not Log4j logs, it's just that it uses Log4j pattern syntax), you can use this Pattern:

Code: Select all

<log4j:event logger="%c" level="%p" timestamp="%d{SSS}" thread="%t"><log4j:message>%m</log4j:message><log4j:properties><log4j:data name="log4japp" value="%mx{log4japp}" /><log4j:data name="log4jmachinename" value="%mx{log4jmachinename}" /></log4j:properties></log4j:event>
Simply type the above Pattern in the field "Log4j or Logback pattern" an you should be good (don't forget to give a name to your Parser at the top of the window, field "Parser name"). Please note that I'm not sure if the indentation of your logs is the correct one due to this forum post format, so if you have any "new line character" in your logs, please add %n in your Pattern to let LogMX know that a new line is expected (also, please be careful about white-space characters).

Here is a screenshot of the Parser I created, which parses the extra fields "log4japp" and "log4jmachinename" (you can remove that if you want):
Please let me know if you have any question or trouble.


Posts: 2
Joined: Thu Sep 21, 2017 7:48 pm

Re: Support for Nlog using log4J format

Post by mbalsam » Fri Sep 22, 2017 6:24 pm


Post Reply