Logging All Properties

Topics: Caching Application Block , Exception Handling Application Block, Logging Application Block
May 24, 2011 at 7:35 PM

I'm new to the Enterprise Library and have been searching the documentation and forums unsuccessfully for a solution.  I'm interested in finding a way to capture all variables at the time of logging.  I'm aware that I can pass a dictionary of key value pairs to LogEntry.ExtendedProperties, but that would rely on knowing which variables to capture.  Does anyone know of a way to automatically capture all available variables/properties?  Thanks in advance.

May 25, 2011 at 5:25 AM


The only way I can think of to achieve this is by using Reflection. The code may look something like this (assuming that all your variable is private): 

        FieldInfo[] variableInfos = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            LogEntry entry = new LogEntry();
            foreach (FieldInfo varInfo in variableInfos)
                entry.ExtendedProperties.Add(varInfo.Name, varInfo.GetValue(this));


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.