當前位置: 首頁>>代碼示例>>C#>>正文


C# Targets.Target類代碼示例

本文整理匯總了C#中NLog.Targets.Target的典型用法代碼示例。如果您正苦於以下問題:C# Target類的具體用法?C# Target怎麽用?C# Target使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Target類屬於NLog.Targets命名空間,在下文中一共展示了Target類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoggingRule

 /// <summary>
 /// Create a new <see cref="LoggingRule" /> with a <paramref name="minLevel"/> and  <paramref name="maxLevel"/> which writes to <paramref name="target"/>.
 /// </summary>
 /// <param name="loggerNamePattern">Logger name pattern. It may include the '*' wildcard at the beginning, at the end or at both ends.</param>
 /// <param name="minLevel">Minimum log level needed to trigger this rule.</param>
 /// <param name="maxLevel">Maximum log level needed to trigger this rule.</param>
 /// <param name="target">Target to be written to when the rule matches.</param>
 public LoggingRule(string loggerNamePattern, LogLevel minLevel, LogLevel maxLevel, Target target)
     : this()
 {
     this.LoggerNamePattern = loggerNamePattern;
     this.Targets.Add(target);
     EnableLoggingForLevels(minLevel, maxLevel);
 }
開發者ID:CjShu,項目名稱:LeagueSharp.SDKEx,代碼行數:14,代碼來源:LoggingRule.cs

示例2: ConfigureForTargetLogging

 /// <summary>
 /// Configures NLog for to log to the specified target so that all messages 
 /// above and including the specified level are output.
 /// </summary>
 /// <param name="target">The target to log all messages to.</param>
 /// <param name="minLevel">The minimal logging level.</param>
 public static void ConfigureForTargetLogging(Target target, LogLevel minLevel)
 {
     LoggingConfiguration config = new LoggingConfiguration();
     LoggingRule rule = new LoggingRule("*", minLevel, target);
     config.LoggingRules.Add(rule);
     LogManager.Configuration = config;
 }
開發者ID:304NotModified,項目名稱:NLog-1,代碼行數:13,代碼來源:SimpleConfigurator.cs

示例3: LoggingRule

 /// <summary>
 /// Initializes a new instance of the <see cref="LoggingRule" /> class.
 /// </summary>
 /// <param name="loggerNamePattern">Logger name pattern. It may include the '*' wildcard at the beginning, at the end or at both ends.</param>
 /// <param name="minLevel">Minimum log level needed to trigger this rule.</param>
 /// <param name="target">Target to be written to when the rule matches.</param>
 public LoggingRule(string loggerNamePattern, LogLevel minLevel, Target target)
 {
     this.Filters = new List<Filter>();
     this.ChildRules = new List<LoggingRule>();
     this.Targets = new List<Target>();
     this.LoggerNamePattern = loggerNamePattern;
     this.Targets.Add(target);
     for (int i = minLevel.Ordinal; i <= LogLevel.MaxLevel.Ordinal; ++i)
     {
         this.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
     }
 }
開發者ID:mattcuba,項目名稱:practicesharp,代碼行數:18,代碼來源:LoggingRule.cs

示例4: AspNetBufferingTargetWrapper

 /// <summary>
 /// Initializes a new instance of the <see cref="AspNetBufferingTargetWrapper" /> class.
 /// </summary>
 /// <param name="wrappedTarget">The wrapped target.</param>
 /// <param name="bufferSize">Size of the buffer.</param>
 public AspNetBufferingTargetWrapper(Target wrappedTarget, int bufferSize)
 {
     WrappedTarget = wrappedTarget;
     BufferSize = bufferSize;
     GrowBufferAsNeeded = true;
 }
開發者ID:epignosisx,項目名稱:NLog.Web,代碼行數:11,代碼來源:AspNetBufferingTargetWrapper.cs

示例5: Add

 /// <summary>
 /// Adds an element with the specified key and value to this TargetDictionary.
 /// </summary>
 /// <param name="key">
 /// The string key of the element to add.
 /// </param>
 /// <param name="value">
 /// The Target value of the element to add.
 /// </param>
 public virtual void Add(string key, Target value)
 {
     this.Dictionary.Add(key, value);
 }
開發者ID:pallmall,項目名稱:WCell,代碼行數:13,代碼來源:TargetDictionary.cs

示例6: TargetWithFilterChain

 public TargetWithFilterChain(Target a, FilterCollection filterChain)
 {
     _target = a;
     _filterChain = filterChain;
     _needsStackTrace = 0;
 }
開發者ID:tdhieu,項目名稱:openvss,代碼行數:6,代碼來源:TargetWithFilterChain.cs

示例7: WrapWithAsyncTargetWrapper

 private static Target WrapWithAsyncTargetWrapper(Target target)
 {
     var asyncTargetWrapper = new AsyncTargetWrapper();
     asyncTargetWrapper.WrappedTarget = target;
     asyncTargetWrapper.Name = target.Name;
     target.Name = target.Name + "_wrapped";
     InternalLogger.Debug("Wrapping target '{0}' with AsyncTargetWrapper and renaming to '{1}", asyncTargetWrapper.Name, target.Name);
     target = asyncTargetWrapper;
     return target;
 }
開發者ID:shadowca,項目名稱:NLog,代碼行數:10,代碼來源:XmlLoggingConfiguration.cs

示例8: TargetWithFilterChain

 /// <summary>
 /// Initializes a new instance of the <see cref="TargetWithFilterChain" /> class.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="filterChain">The filter chain.</param>
 public TargetWithFilterChain(Target target, IList<Filter> filterChain)
 {
     this.Target = target;
     this.FilterChain = filterChain;
 }
開發者ID:CharlieBP,項目名稱:NLog,代碼行數:10,代碼來源:TargetWithFilterChain.cs

示例9: TargetWithFilterChain

 /// <summary>
 /// Initializes a new instance of the <see cref="TargetWithFilterChain" /> class.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="filterChain">The filter chain.</param>
 public TargetWithFilterChain(Target target, IList<Filter> filterChain)
 {
     this.Target = target;
     this.FilterChain = filterChain;
     this.stackTraceUsage = StackTraceUsage.None;
 }
開發者ID:shadowca,項目名稱:NLog,代碼行數:11,代碼來源:TargetWithFilterChain.cs

示例10: WrapWithDefaultWrapper

        private Target WrapWithDefaultWrapper(Target t, XmlReader reader)
        {
            string wrapperType;

            if (!this.TryGetCaseInsensitiveAttribute(reader, "type", out wrapperType))
            {
                // TODO - add error handling
            }

            Target wrapperTargetInstance = this.nlogFactories.TargetFactory.CreateInstance(wrapperType);
            WrapperTargetBase wtb = wrapperTargetInstance as WrapperTargetBase;
            if (wtb == null)
            {
                throw new NLogConfigurationException("Target type specified on <default-wrapper /> is not a wrapper.");
            }

            this.ParseTargetElement(wrapperTargetInstance, reader);
            while (wtb.WrappedTarget != null)
            {
                wtb = wtb.WrappedTarget as WrapperTargetBase;
                if (wtb == null)
                {
                    throw new NLogConfigurationException("Child target type specified on <default-wrapper /> is not a wrapper.");
                }
            }

            wtb.WrappedTarget = t;
            wrapperTargetInstance.Name = t.Name;
            t.Name = t.Name + "_wrapped";

            InternalLogger.Debug("Wrapping target '{0}' with '{1}' and renaming to '{2}", wrapperTargetInstance.Name, wrapperTargetInstance.GetType().Name, t.Name);
            return wrapperTargetInstance;
        }
開發者ID:igalse,項目名稱:NLog,代碼行數:33,代碼來源:XmlLoggingConfiguration.cs

示例11: WrapWithAsyncTarget

 private Target WrapWithAsyncTarget(Target t)
 {
     AsyncTargetWrapper atw = new AsyncTargetWrapper();
     atw.WrappedTarget = t;
     atw.Name = t.Name;
     t.Name = t.Name + "_wrapped";
     InternalLogger.Debug("Wrapping target '{0}' with AsyncTargetWrapper and renaming to '{1}", atw.Name, t.Name);
     return atw;
 }
開發者ID:igalse,項目名稱:NLog,代碼行數:9,代碼來源:XmlLoggingConfiguration.cs

示例12: ParseTargetElement

        private void ParseTargetElement(Target target, XmlReader reader)
        {
            InternalLogger.Trace("ParseTargetElement name={0} type={1}", reader.GetAttribute("name"), reader.GetAttribute("type"));

            var compound = target as CompoundTargetBase;
            var wrapper = target as WrapperTargetBase;

            this.ConfigureObjectFromAttributes(target, reader, this.variables, true);

            if (!reader.IsEmptyElement)
            {
                while (this.MoveToNextElement(reader))
                {
                    string name = reader.LocalName.ToLower(CultureInfo.InvariantCulture);

                    if (compound != null)
                    {
                        if (name == "target" || name == "wrapper" || name == "wrapper-target" || name == "compound-target")
                        {
                            string type;

                            if (!this.TryGetCaseInsensitiveAttribute(reader, "type", out type))
                            {
                                throw new NLogConfigurationException("Missing 'type' attribute on <" + name + " />");
                            }

                            Target newTarget = this.nlogFactories.TargetFactory.CreateInstance(type);
                            if (newTarget != null)
                            {
                                this.ParseTargetElement(newTarget, reader);
                                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;

                            if (!this.TryGetCaseInsensitiveAttribute(reader, "type", out type))
                            {
                                throw new NLogConfigurationException("Missing 'type' attribute on <" + name + " />");
                            }

                            Target newTarget = this.nlogFactories.TargetFactory.CreateInstance(type);
                            if (newTarget != null)
                            {
                                this.ParseTargetElement(newTarget, reader);
                                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;
                        }
                    }

                    this.SetPropertyFromElement(target, reader);
                }
            }
        }
開發者ID:igalse,項目名稱:NLog,代碼行數:80,代碼來源:XmlLoggingConfiguration.cs

示例13: WrapWithDefaultWrapper

        private Target WrapWithDefaultWrapper(Target t, NLogXmlElement defaultParameters)
        {
            string wrapperType = StripOptionalNamespacePrefix(defaultParameters.GetRequiredAttribute("type"));

            Target wrapperTargetInstance = this.ConfigurationItemFactory.Targets.CreateInstance(wrapperType);
            WrapperTargetBase wtb = wrapperTargetInstance as WrapperTargetBase;
            if (wtb == null)
            {
                throw new NLogConfigurationException("Target type specified on <default-wrapper /> is not a wrapper.");
            }

            this.ParseTargetElement(wrapperTargetInstance, defaultParameters);
            while (wtb.WrappedTarget != null)
            {
                wtb = wtb.WrappedTarget as WrapperTargetBase;
                if (wtb == null)
                {
                    throw new NLogConfigurationException("Child target type specified on <default-wrapper /> is not a wrapper.");
                }
            }

            wtb.WrappedTarget = t;
            wrapperTargetInstance.Name = t.Name;
            t.Name = t.Name + "_wrapped";

            InternalLogger.Debug("Wrapping target '{0}' with '{1}' and renaming to '{2}", wrapperTargetInstance.Name, wrapperTargetInstance.GetType().Name, t.Name);
            return wrapperTargetInstance;
        }
開發者ID:shadowca,項目名稱:NLog,代碼行數:28,代碼來源:XmlLoggingConfiguration.cs

示例14: AddTarget

        /// <summary>
        /// Registers the specified target object under a given name.
        /// </summary>
        /// <param name="name">
        /// Name of the target.
        /// </param>
        /// <param name="target">
        /// The target object.
        /// </param>
        public void AddTarget(string name, Target target)
        {
            if (name == null)
            {
                throw new ArgumentException("Target name cannot be null", "name");
            }

            InternalLogger.Debug("Registering target {0}: {1}", name, target.GetType().FullName);
            this.targets[name] = target;
        }
開發者ID:mattcuba,項目名稱:practicesharp,代碼行數:19,代碼來源:LoggingConfiguration.cs

示例15: ParseTargetElement

        private void ParseTargetElement(Target target, NLogXmlElement targetElement)
        {
            var compound = target as CompoundTargetBase;
            var wrapper = target as WrapperTargetBase;

            this.ConfigureObjectFromAttributes(target, targetElement, true);

            foreach (var childElement in targetElement.Children)
            {
                string name = childElement.LocalName;

                if (compound != null)
                {
                    if (IsTargetRefElement(name))
                    {
                        string targetName = childElement.GetRequiredAttribute("name");
                        Target newTarget = this.FindTargetByName(targetName);
                        if (newTarget == null)
                        {
                            throw new NLogConfigurationException("Referenced target '" + targetName + "' not found.");
                        }

                        compound.Targets.Add(newTarget);
                        continue;
                    }

                    if (IsTargetElement(name))
                    {
                        string type = StripOptionalNamespacePrefix(childElement.GetRequiredAttribute("type"));

                        Target newTarget = this.ConfigurationItemFactory.Targets.CreateInstance(type);
                        if (newTarget != null)
                        {
                            this.ParseTargetElement(newTarget, childElement);
                            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 (IsTargetRefElement(name))
                    {
                        string targetName = childElement.GetRequiredAttribute("name");
                        Target newTarget = this.FindTargetByName(targetName);
                        if (newTarget == null)
                        {
                            throw new NLogConfigurationException("Referenced target '" + targetName + "' not found.");
                        }

                        wrapper.WrappedTarget = newTarget;
                        continue;
                    }

                    if (IsTargetElement(name))
                    {
                        string type = StripOptionalNamespacePrefix(childElement.GetRequiredAttribute("type"));

                        Target newTarget = this.ConfigurationItemFactory.Targets.CreateInstance(type);
                        if (newTarget != null)
                        {
                            this.ParseTargetElement(newTarget, childElement);
                            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;
                    }
                }

                this.SetPropertyFromElement(target, childElement);
            }
        }
開發者ID:shadowca,項目名稱:NLog,代碼行數:91,代碼來源:XmlLoggingConfiguration.cs


注:本文中的NLog.Targets.Target類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。