使用 log2j4 显示异常的 toString 内容

Showing the content of toString of exceptions with log2j4

当我们调用 toString() 时,有一些异常 类 格式化详细消息,但 log4j v2 只是显示堆栈跟踪以及使用 Exception(String) 构造函数设置的消息。

有没有办法让 PatternLayout 记录异常的 "toString()" 内容?或者应该将这些异常更改为设置消息而不是使用 toString()?

在约定模式下使用 ex{full} 完成了工作。

使用它的完整转换模式示例:

<Property name="global-pattern">%d{HH:mm:ss.SSS} [%pid/%t] %-5level %logger{36} %M:%L - %msg ex{full}%n</Property>