예제 #1
0
        /// <summary>
        /// Verifies that the logger assembly implements ILogTarget.
        /// </summary>
        /// <param name="filename">The file path to the logger dll to be added.</param>
        /// <returns>
        ///   <c>true</c> if this is a valid target. <c>false</c> otherwise
        /// </returns>
        private static bool VerifyValidLoggerAssembly(string filename)
        {
            Assembly logAsm = Assembly.LoadFile(filename);

            foreach (Type item in logAsm.GetTypes())
            {
                /* Run through any interfaces this logger may implement..we want the ILogTarget */
                Type[] iface = item.GetInterfaces();
                if (iface.Length == 0)
                {
                    return(false);
                }

                foreach (Type t in iface)
                {
                    if (iface[0] != typeof(ILogTarget))
                    {
                        continue;
                    }

                    /* Create a temporary version of the logger to get any parameters */
                    ILogTarget tempLogger = (ILogTarget)Activator.CreateInstance(item);
                    /* Call the interface method to get info */
                    tempLogger.CallParameterForm();

                    return(true);
                }
            }
            return(false);
        }