本文整理汇总了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);
}
示例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;
}
示例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));
}
}
示例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;
}
示例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);
}
示例6: TargetWithFilterChain
public TargetWithFilterChain(Target a, FilterCollection filterChain)
{
_target = a;
_filterChain = filterChain;
_needsStackTrace = 0;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
}