Can we set the characters limited to 10 characters in log4net %property?

这一生的挚爱 提交于 2019-12-13 01:05:18

问题


This is my threadContext exception message property

log4net.ThreadContext.Properties["excmessage"] = ex.Message;

I want to get the first 10 characters of exception message property using log4net.

This is the line in Log4net.config:

%property{excmessage}

回答1:


As far as I can tell you can only "truncate from the beginning" which means you get the end of the string:

%.10property{excmessage}

Here is a link to the documentation: http://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Layout.PatternLayout.html

I suggest that you fill two properties: one with the exception message and the other with the truncated message.



来源:https://stackoverflow.com/questions/50228371/can-we-set-the-characters-limited-to-10-characters-in-log4net-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!