Esempio n. 1
0
        /// <summary>
        /// Scans the specified assembly for types marked with <see cref="ConditionMethodsAttribute" /> and adds
        /// them to the factory. Optionally it prepends the specified text to layout renderer names to avoid
        /// naming collisions.
        /// </summary>
        /// <param name="theAssembly">The assembly to be scanned for layout renderers.</param>
        /// <param name="prefix">The prefix to be prepended to layout renderer names.</param>
        public static void AddConditionMethodsFromAssembly(Assembly theAssembly, string prefix)
        {
            try
            {
                InternalLogger.Debug("AddLogEventConditionsFromAssembly('{0}')", theAssembly.FullName);
                foreach (Type t in theAssembly.GetTypes())
                {
                    if (t.IsDefined(typeof(ConditionMethodsAttribute), false))
                    {
                        if (PlatformDetector.IsSupportedOnCurrentRuntime(t))
                        {
                            foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Static))
                            {
                                ConditionMethodAttribute[] malist = (ConditionMethodAttribute[])mi.GetCustomAttributes(typeof(ConditionMethodAttribute), false);

                                foreach (ConditionMethodAttribute ma in malist)
                                {
                                    if (PlatformDetector.IsSupportedOnCurrentRuntime(mi))
                                    {
                                        AddConditionMethod(ma.Name, mi);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InternalLogger.Error("Failed to add LogEventConditions from '" + theAssembly.FullName + "': {0}", ex);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Scans the specified assembly for types marked with <see cref="TargetAttribute" /> and adds
 /// them to the factory. Optionally it prepends the specified text to the target names to avoid
 /// naming collisions.
 /// </summary>
 /// <param name="theAssembly">The assembly to be scanned for targets.</param>
 /// <param name="prefix">The prefix to be prepended to target names.</param>
 public static void AddTargetsFromAssembly(Assembly theAssembly, string prefix)
 {
     try
     {
         InternalLogger.Debug("AddTargetsFromAssembly('{0}')", theAssembly.FullName);
         foreach (Type t in theAssembly.GetTypes())
         {
             TargetAttribute[] attributes = (TargetAttribute[])t.GetCustomAttributes(typeof(TargetAttribute), false);
             if (attributes != null)
             {
                 foreach (TargetAttribute attr in attributes)
                 {
                     if (PlatformDetector.IsSupportedOnCurrentRuntime(t))
                     {
                         AddTarget(prefix + attr.Name, t);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         InternalLogger.Error("Failed to add targets from '" + theAssembly.FullName + "': {0}", ex);
     }
 }