Enterprise Library 5 How to change event log format?

368 Views Asked by At

Whilst the Ent Lib 5 is very easy to get logging working; when the data is logged to the event log it is in the format (as seen via XML tab> as <EventData> A B C D </>" . I need to get it in the form <EventData><Data Name=A/><Data Name=B/>....". Does anyone know if there a way of doing this using the Ent Lib 5 logging block or the like...

1

There are 1 best solutions below

0
On

You can customize your text formatter for writing it as xml. Something like this:

<add template="&lt;Timestamp&gt;{timestamp}&lt;/Timestamp&gt;" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging" name="Text Formatter" />

So the output is something like:

<EventData><Data><Timestamp>2/13/2013 7:59:32 PM</Timestamp></Data></EventData>

If you want to serialize an object to xml you can write a custom formatter and use it. Derive it from LogFormatter and override the Format method. And serialize your LogEntry to xml.