Some additional Custom PropertyReaders

Oct 5, 2009 at 11:17 AM

Hi

Could you please add the following custom property readers to the the Ukadc logger?
I've added them for my purpose, but don't want to have them overwritten by a new version of your logging library.

Thanks & kind regards,
Christian Broennimann

// IMPORTANT for each new PropertyReader:
// add a configuration code line in the method PropertyReaderFactory.AddInternalTokens()

using System;
using System.Diagnostics;

namespace Ukadc.Diagnostics.Utils.PropertyReaders
{
    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the User Login Name using the <see cref="System.Security.Principal.WindowsIdentity"/> property.
    /// </summary>
    public class UserNamePropertyReader : StringPropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            return true;
        }
    }

    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the Executing Assembly Version using the <see cref="System.Reflection.Assembly"/> property.
    /// </summary>
    public class ExecutingAssemblyVersionPropertyReader : StringPropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            return true;
        }
    }

    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the Dot Net Version using the <see cref="Environment.Version"/> property.
    /// </summary>
    public class DotNetVersionPropertyReader : StringPropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = Environment.Version.ToString();
            return true;
        }
    }

    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the Operating System Version using the <see cref="Environment.OSVersion.VersionString"/> property.
    /// </summary>
    public class OperatingSystemVersionPropertyReader : StringPropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = Environment.OSVersion.VersionString;
            return true;
        }
    }

    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the Temp Path using the <see cref="System.IO.Path"/> property.
    /// </summary>
    public class TempPathPropertyReader : StringPropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = System.IO.Path.GetTempPath();
            return true;
        }
    }

    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the Physical Memory used using the <see cref="Environment.WorkingSet"/> property.
    /// </summary>
    public class PhysicalMemoryUsedPropertyReader : StringPropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = (Environment.WorkingSet / 1024 / 1024).ToString("0.00") + " MB";
            return true;
        }
    }

    /// <summary>
    /// A <see cref="PropertyReader"/> that gets the value of the Last System Start using the <see cref="Environment.TickCount"/> property.
    /// </summary>
    public class LastSystemStartPropertyReader : DateTimePropertyReader
    {
        public override bool TryGetValue(out object value, TraceEventCache cache, string source,
                                         TraceEventType eventType, int id, string formatOrMessage,
                                         object[] data)
        {
            value = DateTime.Now.AddMilliseconds(-Environment.TickCount);
            return true;
        }
    }
}

Coordinator
Oct 6, 2009 at 2:13 PM

Thanks Christian,

These look great. In fact, we're now thinking of extending the FastPropertyGetter so you can actually invoke static methods like this from config. i.e. {System.IO.Path.GetTempPath()} or something.

Thanks again

Josh