Enterprise Library Logging Extended Properties Fails on Server

1k Views Asked by At

I've got a standard enterprise library text formatter, with the default formatting. The log file is properly created, but remains empty. If I remove the last formatting option, with the extended properties (see below) it starts working. If I put it back, the log remains empty and I have no clue where to search for the error.

template="Tim...
Extended Properties: {dictionary({key} - {value}{newline})}"

(Yes I can run it with that exact abbreviated template to trigger the error). If I remove the {dictionary({key} - {value}{newline})} part it starts logging. The problem only occurs on the test server, on my local dev machine it works as expected, outputting my extended properties.

I've tried setting up a separate logging errors destination, but with no luck. Nothing gets logged there.

3

There are 3 best solutions below

0
On BEST ANSWER

The ExtendedProperties dictionary must not contain nulls. This causes logging to fail because Enterprise Library does not expect null objects in this dictionary. To diagnose if this is your problem, you configure the 'Logging Errors & Warnings' category to log somewhere, then you should be able to see any errors that are occuring when logging.

0
On

I think @TimB is probably right.

There is an open issue related to this: "The reason why the original exception is not reported is that when reporting the exception another TextFormatter is used and another exception is thrown which is caught and swallowed (although the logging failure event is fired)."

The workaround would be not to populate nulls in the ExtendedProperties. Or perhaps a custom formatter.

0
On

Another issue I encountered causing missing extended properties, is some overloads of Logger.Write don't treat the object as an exception, and thus don't log extended properties.

One option is cast exception.Data to a Dictionary and pass that as the third properties parameter.

Second option is instead use ExceptionPolicy.HandleException to log the exception(assuming you exception policy sends the exception to an appropriate log category).