我们可以在log4net%property中将字符限制为10个字符吗? [英] Can we set the characters limited to 10 characters in log4net %property?

查看:390
本文介绍了我们可以在log4net%property中将字符限制为10个字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的threadContext异常消息属性

This is my threadContext exception message property

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

我想使用log4net获得异常消息属性的前10个字符.

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

这是Log4net.config中的行:

This is the line in Log4net.config:

%property{excmessage}

推荐答案

据我所知,您只能从头开始截断",这意味着您可以得到字符串的结尾:

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

%.10property{excmessage}

这里是文档的链接: http://logging.apache. org/log4net/log4net-1.2.11/release/sdk/log4net.Layout.PatternLayout.html

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.

这篇关于我们可以在log4net%property中将字符限制为10个字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆