Exemplo n.º 1
0
        private void ConfigureTargetFromXmlElement(Target target, XmlElement element)
        {
            NLog.Targets.Compound.CompoundTargetBase compound = target as NLog.Targets.Compound.CompoundTargetBase;
            NLog.Targets.Wrappers.WrapperTargetBase  wrapper  = target as NLog.Targets.Wrappers.WrapperTargetBase;

            PropertyHelper.ConfigureObjectFromAttributes(target, element.Attributes, _variables, true);

            foreach (XmlElement el in PropertyHelper.GetChildElements(element))
            {
                string name = el.LocalName;

                if (compound != null)
                {
                    if ((name == "target" || name == "wrapper" || name == "wrapper-target" || name == "compound-target"))
                    {
                        string type      = GetCaseInsensitiveAttribute(el, "type");
                        Target newTarget = TargetFactory.CreateTarget(type);
                        if (newTarget != null)
                        {
                            ConfigureTargetFromXmlElement(newTarget, el);
                            if (newTarget.Name != null)
                            {
                                // if the new target has name, register it
                                AddTarget(newTarget.Name, newTarget);
                            }
                            compound.Targets.Add(newTarget);
                        }
                        continue;
                    }
                }

                if (wrapper != null)
                {
                    if ((name == "target" || name == "wrapper" || name == "wrapper-target" || name == "compound-target"))
                    {
                        string type      = GetCaseInsensitiveAttribute(el, "type");
                        Target newTarget = TargetFactory.CreateTarget(type);
                        if (newTarget != null)
                        {
                            ConfigureTargetFromXmlElement(newTarget, el);
                            if (newTarget.Name != null)
                            {
                                // if the new target has name, register it
                                AddTarget(newTarget.Name, newTarget);
                            }
                            if (wrapper.WrappedTarget != null)
                            {
                                throw new NLogConfigurationException("Wrapped target already defined.");
                            }
                            wrapper.WrappedTarget = newTarget;
                        }
                        continue;
                    }
                }

                PropertyHelper.SetPropertyFromElement(target, el, _variables);
            }
        }
Exemplo n.º 2
0
 private static Exception WriteNumberAsyncLogEventsStartingAt(int startIndex, int count, WrapperTargetBase wrapper)
 {
     Exception lastException = null;
     for (int i = startIndex; i < startIndex + count; i++)
     {
         wrapper.WriteAsyncLogEvent(
             new LogEventInfo(LogLevel.Debug, "test", $"Hello {i}").WithContinuation(ex => lastException = ex));
     }
     return lastException;
 }