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}
Techgeeks1
  • 556
  • 1
  • 4
  • 18
  • 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. – sgmoore May 08 '18 at 08:14
  • @sgmoore i have full text message in my log but i want it shorter to show this in email.I want it using log4net. – Techgeeks1 May 08 '18 at 08:54

1 Answers1

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.

Stefan Egli
  • 17,398
  • 3
  • 54
  • 75