LogEntry ExtendedProperties

Topics: Building and extending application blocks, Logging Application Block
May 18, 2010 at 7:49 PM

 

Can you provide or point me to an example of how to get the values from the ExtendedProperties collection of the LogEntry object?

Thanks, nplumb

May 18, 2010 at 10:13 PM
Edited May 18, 2010 at 10:15 PM

Hello,

Using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
Using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;

public static void GetExtendedProperties(ref Dictionary<string, object> extendedProperties)

  try { 
    if (extendedProperties == null) extendedProperties = new Dictionary<string, object>(); 
        
    // ComPlus information - ActivityID, ApplicationID, TransactionID, DirectCallerAccountName, OriginalCallerAccountName 
    new ComPlusInformationProvider().PopulateDictionary(extendedProperties); 
        
    // Debug information - StackTrace. 
    new DebugInformationProvider().PopulateDictionary(extendedProperties); 
        
    // Managed security context - AuthenticationType, IdentityName, IsAuthenticated. 
    new ManagedSecurityContextInformationProvider().PopulateDictionary(extendedProperties); 
        
    // Unmanaged security context - CurrentUser, ProcessAccountName. 
    new UnmanagedSecurityContextInformationProvider().PopulateDictionary(extendedProperties); 
  } 
  catch (Exception) { 
    throw; 
  }
}

To add them to an exception, iterate the dictionary and add the key and value to ex.Data.Add(key, value);

To get them from the LogEntry, iterate the LogEntry.ExtendedProperties collection.

Good Luck!

May 19, 2010 at 2:14 PM

 

Thanks for the help, what I was having problems with was iterating thru the LogEntry.ExtendedProperties collection, do you have an example of that action?

Thanks, nplumb

May 19, 2010 at 3:14 PM

ExtendedProperties is an object type of Dictionary<string,object>, you can try doing your iteration something like this

            IDictionary<string,object> extendedProperties = log.ExtendedProperties;
            
            foreach (KeyValuePair<string, object> keyValue in extendedProperties)
            {
                // do iteration of the dictionary key values here
            }

HTH.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com