title: Log4j2 JsonTemplateLayout - log message field as json
body: <p>I have this <code>log4j2.xml</code>:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Configuration&gt;
  &lt;Appenders&gt;
      &lt;Console name=&quot;JsonAppender&quot; target=&quot;SYSTEM_OUT&quot;&gt;
          &lt;JsonTemplateLayout eventTemplateUri=&quot;classpath:EcsLayout.json&quot; /&gt;
      &lt;/Console&gt;
  &lt;/Appenders&gt;
  &lt;Loggers&gt;
      &lt;Logger name=&quot;JsonLogger&quot; level=&quot;INFO&quot; additivity=&quot;false&quot;&gt;
          &lt;AppenderRef ref=&quot;JsonAppender&quot;/&gt;
      &lt;/Logger&gt;
      &lt;Root level=&quot;info&quot;&gt;
          &lt;AppenderRef ref=&quot;JsonAppender&quot;/&gt;
      &lt;/Root&gt;
  &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  <p>In my code I have a logging statement like:</p>
  <pre><code>HashMap logMap = new HashMap&lt;&gt;();
          logMap.put(&quot;appId&quot;, &quot;123456789&quot;);
          logMap.put(&quot;action&quot;, &quot;Received request&quot;);
  
          logger.info(new ObjectMessage(logMap));
  </code></pre>
  <p>In my log I get this:</p>
  <pre><code> {
          &quot;@timestamp&quot;: &quot;2022-02-02T10:52:56.100Z&quot;,
          &quot;ecs.version&quot;: &quot;1.2.0&quot;,
          &quot;log.level&quot;: &quot;INFO&quot;,
          &quot;message&quot;: &quot;{appId=123456789, action=Received request}&quot;,
          &quot;process.thread.name&quot;: &quot;main&quot;,
          &quot;log.logger&quot;: &quot;org.xxxx.App&quot; 
  }
  </code></pre>
  <p>That's ok but I want the <code>message</code> to be in json, so would like:</p>
  <pre><code>&quot;message&quot;: {
                &quot;appId&quot;: &quot;123456789&quot;, 
                &quot;action&quot;: &quot;Received request&quot;
  }
  </code></pre>
  <p>I know using <code>JsonLayout</code> you had to specify <code>objectMessageAsJsonObject=&quot;true&quot;</code>, but suspect it's a bit more nuanced when using <code>JsonTemplateLayout</code>.</p>
  <p>TIA.</p>