user208478
user208478

Reputation: 125

NLog isn't writing an empty custom event propperties into SqlDatabase

I have a few custom event layouts in my configuration like this {event-properties:item=SomeCustomProperty}

Filling them out like this:

var testLogger = testNLogFactory.GetLogger("Test");
LogEventInfo theEvent = new LogEventInfo(LogLevel.Debug, null, "Test");
theEvent.Properties.Add("SomeCustomProperty", null);
testLogger.Debug(theEvent);

I have 2 targets, file and database. File target works fine but in case of database this record won't be written as long as SomeCustomProperty value stays null. If I replace null with any value, it works just fine.

The corresponding table in the database is correct and allows NULL values in SomeCustomProperty but if {event-properties:item=SomeCustomProperty} has no value the record won't be added to the database.

Is there any reason for this behavior? Is there any workaround?

Upvotes: 0

Views: 167

Answers (1)

Julian
Julian

Reputation: 36700

All layout renderers, like ${event-properties:item=SomeCustomProperty}, will return an empty string if empty, and not null

Upvotes: 1

Related Questions