Log all text sent to listener as a single string entry

Topics: Logging Application Block
Mar 19, 2012 at 5:28 AM

I have a strange request.  I have a custom log table which can't be altered.  It logs the output of console apps which are run on their seperate schedules.  The request is to have all the log entries sent to the listener during the lifetime of the console run to be sent to a field in the custom log table.  One approach which has worked but i am not fond of it, was to create a custom listener which adds the messages to a string builder.  The listener is added at runtime through code.  Then the last line of the console is to get the string entries from the string builder in the listener and send them to the db using a stored proc.  I would prefer if i could keep all the code in a listener and wouldnt have to have any logic added to the console app.  I was considering a listener with the db code in the Dispose method, but it doesnt seem to be called ever.  Any advise is appreciated.


Thank you

Mar 19, 2012 at 6:30 AM

If you Dispose the LogWriter explicitly the trace listeners should also be Disposed.  It looks like you need to manually call Dispose since there is no Finalizer defined.  E.g.

using (var logger = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>())

Randy Levy
Enterprise Library support engineer