Adding Username to Logging application block

Topics: Logging Application Block
Jan 17, 2008 at 2:09 PM
I am usingn the January 2006 (2.0) Enterprise Library. I have a need to add a username entry to the logging application block (utimately logging the information in the database). Do I need to extend the Logging application block or do I need to modify the logging applcation block? I am looking for some starting help to determine where the modification need to be made. I will be adding a column to the LOG database table called USER_NAME (as well as modify the stored procedures). This will hold the current logged in user name for my web application. Do I need to modify the LogEntry class to add the username as a property? Any help would be appreciated.
Jan 21, 2008 at 11:42 AM
Hi,

You can either modify the existing trace listener or create one of your own (likely very similar to the existing one). The former is easier, but the latter is better.

Regarding your question about the LogEntry, you need to either add the property or an entry to the ExtendedProperties dictionary if you want to log across processes (eg using the distributor service). If you don't want to modify the code, you can use the UnmanagedSecurityContextInformationProvider to populate the extended properties for you. Of course this means you need to invoke the information provider each time you log. You can see sample code for this in the help file.

Hope this helps,
Fernando
Jan 23, 2008 at 4:52 PM
Thanks Fernando! I see that the ManagedSecurityContextInformationProvider will give me the information that I need (specifically the IdentityName, which is where I am storing the logged in user for the application). It looks like the ManagedSecurityContextInformationProvider dictionary entry creates a second log entry without a TITLE, which fails entry into the database trace listener. I need to have one column in my table for "USERNAME" that contains the user name on each log entry. I know that I'll have to modify the tracelistener to add the new property. Do I have to modify the LogEntry too to make sure the value gets into the database?

Thanks


fsimonazzi wrote:
Hi,

You can either modify the existing trace listener or create one of your own (likely very similar to the existing one). The former is easier, but the latter is better.

Regarding your question about the LogEntry, you need to either add the property or an entry to the ExtendedProperties dictionary if you want to log across processes (eg using the distributor service). If you don't want to modify the code, you can use the UnmanagedSecurityContextInformationProvider to populate the extended properties for you. Of course this means you need to invoke the information provider each time you log. You can see sample code for this in the help file.

Hope this helps,
Fernando