public String doLayout(ILoggingEvent event) {
        StringBuilder buf = new StringBuilder();
        startNewTableIfLimitReached(buf);

        boolean odd = true;
        if (((counter++) & 1) == 0) {
            odd = false;
        }

        String level = event.getLevel().toString().toLowerCase();

        buf.append(LINE_SEPARATOR);
        buf.append("<tr class=\"");
        buf.append(level);
        if (odd) {
            buf.append(" odd\">");
        } else {
            buf.append(" even\">");
        }
        buf.append(LINE_SEPARATOR);

        Converter<ILoggingEvent> c = head;
        while (c != null) {
            appendEventToBuffer(buf, c, event);
            c = c.getNext();
        }
        buf.append("</tr>");
        buf.append(LINE_SEPARATOR);

        if (event.getThrowableProxy() != null) {
            throwableRenderer.render(buf, event);
        }
        return buf.toString();
    }
@Test
    public void layoutWithException() throws Exception {
        layout.setPattern("%level %thread %msg %ex");
        LoggingEvent le = createLoggingEvent();
        le.setThrowableProxy(new ThrowableProxy(new Exception("test Exception")));
        String result = layout.doLayout(le);

        String stringToParse = layout.getFileHeader();
        stringToParse = stringToParse + layout.getPresentationHeader();
        stringToParse += result;
        stringToParse += "</table></body></html>";

        // System.out.println(stringToParse);

        Document doc = parseOutput(stringToParse);
        Element rootElement = doc.getRootElement();
        Element bodyElement = rootElement.element("body");
        Element tableElement = bodyElement.element("table");
        List<Element> trElementList = tableElement.elements();
        Element exceptionRowElement = trElementList.get(2);
        Element exceptionElement = exceptionRowElement.element("td");

        assertEquals(3, tableElement.elements().size());
        assertTrue(exceptionElement.getText().contains("java.lang.Exception: test Exception"));
    }