I am attempting to use LogEventInfo.Properties in my code to log custom data to the renderer. One of the objects I am adding is a DateTime object. In the event context layout renderer, I would like to be able to specify the date format string that the DateTime object should be rendered with. Is this possible?
To back up... my goal is to log several custom data fields and allow the user to choose what fields get rendered in the log (and how in the case of DateTime) with the NLog configuration. As best as I can tell, using the LogEventInfo is the easiest way to log custom data. How can I do this, and control the date format string in the NLog configuration?
OK, so my current solution is to implement my own EventContextLayoutRenderer. It is mostly identical to the original one but has an additional format property and checks if the LayoutEventInfo property value is a DateTime object. If the value is a DateTime object it formats the DateTime according the format property and appends that to the string builder. This was the only solution that I could come up with... please let me know if there is a more elegant solution. I would prefer not to have the extensions element in my NLog configuration (adds clutter), but that appears to be required with my solution.