1

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.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • 1
    Does the LogEntry's ExtendedProperties dictionary contain anything? Is it possible that an object in that dictionary is null or throwing an exception in the ToString()? If you configure the 'Logging Errors & Warnings' category to log somewhere, you should be able to see any errors that are occuring when logging. – Tim B May 24 '12 at 14:36
  • I included source file and line number info in the ExtendedProperties. On the test machine, the debug info files were missing - giving nulls. If you post your comment as an answer I'll accept it. – Anders Abel May 27 '12 at 08:47

3 Answers3

2

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.

Randy Levy
  • 22,566
  • 4
  • 68
  • 94
1

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.

Tim B
  • 2,340
  • 15
  • 21
0

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).

AaronLS
  • 37,329
  • 20
  • 143
  • 202