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

1

1

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}
Faa answered 8/5, 2018 at 7:38 Comment(2)
Not sure if you can do this in the log4net config, but you could do log4net.ThreadContext.Properties["excmessage"] = ex.Message.Substring(0,Math.Min(ex.Message.Length,10)); Wouldn't recommend it unless you have the full error message logged somewhere else.Abeyta
@Abeyta i have full text message in my log but i want it shorter to show this in email.I want it using log4net.Faa
L
0

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.

Lona answered 8/5, 2018 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.