Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net inserting (null) into custom column

Added a custom column as suggested here. Things are working fine when ever I log something into this column using the code line

log4net.GlobalContext.Properties["CustomColumn"] = "Custom value";

But if I pass null instead as below

log4net.GlobalContext.Properties["CustomColumn"] = null;

this is logged as (null)(a string null included in brakets). This also happens if I do not log at all, like I comment the code as shown below.

//log4net.GlobalContext.Properties["CustomColumn"] = null;

So the question is, is there a way to make it actually null in the database, instead of a string - (null). I am using ms sql server 2008 r2

like image 331
VivekDev Avatar asked Sep 18 '26 00:09

VivekDev


2 Answers

I have modified the insert statement of the commandText value in Web.config file to

"INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception],[BrowserCapabilities]) VALUES (@log_date, @thread, @log_level, 
        @logger, @message, @exception, CASE WHEN @BrowserCapabilities = '' OR @BrowserCapabilities = '(null)' THEN NULL ELSE @BrowserCapabilities END )" 

Now this works fine.

like image 78
VivekDev Avatar answered Sep 20 '26 13:09

VivekDev


try this

log4net.GlobalContext.Properties["CustomColumn"] = DBNull.Value;
like image 25
Szeki Avatar answered Sep 20 '26 14:09

Szeki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!