Add column for application id in exception table/log

Topics: Exception Handling Application Block, General discussion, Logging Application Block
Nov 29, 2012 at 7:00 PM

I have configured EntLib 5 and have an exception policy to write to the database (using out of the box handlers).

I am planning on having multiple applications using same policies and so I would like to be able to identify the different exceptions in the table by the application that created them.

I have read that I cannot change the 'title' column dynamically.

 

I am planning on putting the policies in the machine.configs so end users must be able to establish the application id before the exception handler picks up and writes to the database.

Is this possible?

thx

Nov 30, 2012 at 4:48 AM

I assume by multiple applications you mean multiple applications all running on the same server so there could be many application ids per server.

Yes, you are right -- the Exception Handling Logging configuration is static.  Enterprise Library supports parent configuration that is merged with local configuration.  However, that would require users of your framework (i.e. applications) to recreate a fair bit of the configuration (which I assume you want to avoid).

One way to get what you want without any coding would be if you could add the application id to the exception Data property.  The information would get added to the extended properties for logging.  This assumes that the extended properties are being logged (out of the box Database Trace Listener does not) and also that there is an easy/elegant way to add that application id (could be a facade you provide).

Otherwise to get the behavior you want you will have to do some work.  One approach would be to write a custom trace listener that picks up the additional information.  This could be read from config (e.g. local appSettings) or perhaps a singleton object that the application would set at application startup and then would include the application id when writing to the destination.  You could also implement a Logging Exception Handler that does something similar (set the title to dynamic application id).  

Another approach would be to provide an assembly that can be called and will programmatically configure at runtime the proper configuration with the application id.  

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com