This project is read-only.



PropertyReaders are an important part of the implementation of the Ukadc.Diagnostics logging system. In short, they read data from the event and allow it to be used in a listener or filter. Perhaps more importantly, they aim to do this in a performant way and avoid using Reflection (or at least only once per appdomain lifetime).

PropertyReaders are used in conjunction with Tokens to allow them to be used easily. A token is just a string representation of a particular PropertyReader.

You can create your own PropertyReaders by inheriting from Ukadc.Diagnostics.Utils.PropertyReaders.PropertyReader. This is a sample propertyReader that grabs the ProcessName using the System.Diagnostics.Process.GetCurrentProcess method.

public class ProcessNamePropertyReader : PropertyReader
    private StringComparator _stringComparator = new StringComparator();

    public override Type PropertyType
        get { return typeof(string); }

    public override IComparator Comparator
        get { return _stringComparator; }

    public override bool TryGetValue(out object value, TraceEventCache cache, string source, TraceEventType eventType,
                                    int id, string formatOrMessage, object[] args, object data1, object[] data)
        value = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
        return true;

Most of the PropertyReaders that ship with Ukadc.Diagnostics retrieve their values from the (long) list of parameters that are passed to the TryGetValue method.

The Comparator is used by the PropertyFilter to pefrorm comparisons on the value returned by the PropertyReader. Note that in this instance (because the ProcessName is a string) we chose to use the in-built StringComparator. Check out the page on Comparators for more information. As a rule of thumb though, use the StringComparator for strings and the NumericComparator for everything else (it doesn't have to be 'numeric', just implement IComparable).


Most of the PropertyReaders that ship with Ukadc.Diagnostics are 'hard-wired' like the ProcessName above and don't use reflection. However, there is a special type of PropertyReader called the DynamicPropertyReader - find out more by following the link.

Last edited Mar 24, 2008 at 7:40 PM by joshtwist, version 4


No comments yet.