0

I am using extra property which has to be logged into database at the time of exception. Please check at this link for extra property usage. https://www.codeproject.com/articles/140911/log4net-tutorial

I want to add a check in webconfig if that property is not initialized do something otherwise if that property is initialized do something else. How to do that?

From comment:

log4net.ThreadContext.Properties["Property1"] = someval; I am setting this property in some cases. But when I use %property{Property1} it displays values for cases which I have set. But for those cases where I have not specified values it logs (null) into database column. How to avoid null value and add blank space?

stuartd
  • 70,509
  • 14
  • 132
  • 163
Sachit Murarka
  • 137
  • 2
  • 12
  • Please show **your** code instead of linking to a tutorial and properly describe what you are trying to do. – stuartd Feb 20 '17 at 14:48
  • @stuartd: log4net.ThreadContext.Properties["Property1"] = someval; I am setting this property in some cases. But when I use %property{Property1} it displays values for cases which I have set. But for those cases where I have not specified values it logs (null) into database column. How to avoid null value and add blank space? – Sachit Murarka Feb 21 '17 at 05:11

1 Answers1

2

Use the NullText property.

Use this value to indicate a null has been encountered while outputting a string representation of an item.

The default value is (null). This value can be overridden by specifying a value for the log4net.NullText appSetting in the application's .config file.

You can set this in config:

<appSettings>
  <add key="log4net.NullText" value="" />
</appSettings>

Or in code:

log4net.Util.SystemInfo.NullText = string.Empty;

Note that if you are using an old version of log4net then the value has to be a single space rather than empty.

Community
  • 1
  • 1
stuartd
  • 70,509
  • 14
  • 132
  • 163