コード例 #1
0
        /// <summary>
        /// Validates the configuration.
        /// </summary>
        internal void ValidateConfig()
        {
            var roots = new List <object>();

            var loggingRules = LoggingRules.ToList();

            foreach (LoggingRule rule in loggingRules)
            {
                roots.Add(rule);
            }

            var targetList = _targets.Values.ToList();

            foreach (Target target in targetList)
            {
                roots.Add(target);
            }

            _configItems = ObjectGraphScanner.FindReachableObjects <object>(true, roots.ToArray());

            // initialize all config items starting from most nested first
            // so that whenever the container is initialized its children have already been
            InternalLogger.Info("Found {0} configuration items", _configItems.Count);

            foreach (object o in _configItems)
            {
                PropertyHelper.CheckRequiredParameters(o);
            }
        }
コード例 #2
0
        /// <summary>
        /// Log to the internal (NLog) logger the information about the <see cref="Target"/> and <see
        /// cref="LoggingRule"/> associated with this <see cref="LoggingConfiguration"/> instance.
        /// </summary>
        /// <remarks>
        /// The information are only recorded in the internal logger if Debug level is enabled, otherwise nothing is
        /// recorded.
        /// </remarks>
        internal void Dump()
        {
            if (!InternalLogger.IsDebugEnabled)
            {
                return;
            }

            InternalLogger.Debug("--- NLog configuration dump ---");
            InternalLogger.Debug("Targets:");
            var targetList = _targets.Values.ToList();

            foreach (Target target in targetList)
            {
                InternalLogger.Debug("{0}", target);
            }

            InternalLogger.Debug("Rules:");
            var loggingRules = LoggingRules.ToList();

            foreach (LoggingRule rule in loggingRules)
            {
                InternalLogger.Debug("{0}", rule);
            }

            InternalLogger.Debug("--- End of NLog configuration dump ---");
        }
コード例 #3
0
        /// <summary>
        /// Flushes any pending log messages on all appenders.
        /// </summary>
        /// <param name="asyncContinuation">The asynchronous continuation.</param>
        internal void FlushAllTargets(AsyncContinuation asyncContinuation)
        {
            InternalLogger.Trace("Flushing all targets...");

            var uniqueTargets = new List <Target>();
            var loggingRules  = LoggingRules.ToList();

            foreach (var rule in loggingRules)
            {
                var targetList = rule.Targets.ToList();
                foreach (var target in targetList)
                {
                    if (!uniqueTargets.Contains(target))
                    {
                        uniqueTargets.Add(target);
                    }
                }
            }

            AsyncHelpers.ForEachItemInParallel(uniqueTargets, asyncContinuation, (target, cont) => target.Flush(cont));
        }