Esempio n. 1
0
    static void Main(string[] args)
    {
        FileTarget wrappedTarget = new FileTarget();
        wrappedTarget.FileName = "${basedir}/file.txt";

        PostFilteringTargetWrapper postFilteringTarget = new PostFilteringTargetWrapper();
        postFilteringTarget.WrappedTarget = wrappedTarget;

        // set up default filter
        postFilteringTarget.DefaultFilter = "level >= LogLevel.Info";

        FilteringRule rule;

        // if there are any warnings in the buffer
        // dump the messages whose level is Debug or higher

        rule = new FilteringRule();
        rule.Exists = "level >= LogLevel.Warn";
        rule.Filter = "level >= LogLevel.Debug";

        postFilteringTarget.Rules.Add(rule);

        BufferingTargetWrapper target = new BufferingTargetWrapper();
        target.BufferSize = 100;
        target.WrappedTarget = postFilteringTarget;

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");
        logger.Debug("log message");
    }
Esempio n. 2
0
        protected void Application_Start(object sender, EventArgs e)
        {
            FileTarget fileTarget = new FileTarget();
            fileTarget.FileName = "${basedir}/logfile.txt";

            PostFilteringTargetWrapper postfilteringTarget = new PostFilteringTargetWrapper();
            ASPNetBufferingTargetWrapper aspnetBufferingTarget = new ASPNetBufferingTargetWrapper();
            aspnetBufferingTarget.WrappedTarget = postfilteringTarget;
            postfilteringTarget.WrappedTarget = fileTarget;

            postfilteringTarget.DefaultFilter = "level >= LogLevel.Info";
            FilteringRule rule = new FilteringRule();
            rule.Exists = "level >= LogLevel.Warn";
            rule.Filter = "level >= LogLevel.Debug";
            postfilteringTarget.Rules.Add(rule);

            SimpleConfigurator.ConfigureForTargetLogging(aspnetBufferingTarget, LogLevel.Debug);
        }
Esempio n. 3
0
 /// <summary>
 /// Removes the first occurrence of a specific FilteringRule from this FilteringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The FilteringRule value to remove from this FilteringRuleCollection.
 /// </param>
 public virtual void Remove(FilteringRule value)
 {
     this.List.Remove(value);
 }
Esempio n. 4
0
 /// <summary>
 /// Inserts an element into the FilteringRuleCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the FilteringRule is to be inserted.
 /// </param>
 /// <param name="value">
 /// The FilteringRule to insert.
 /// </param>
 public virtual void Insert(int index, FilteringRule value)
 {
     this.List.Insert(index, value);
 }
Esempio n. 5
0
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this FilteringRuleCollection
 /// </summary>
 /// <param name="value">
 /// The FilteringRule value to locate in the FilteringRuleCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(FilteringRule value)
 {
     return(this.List.IndexOf(value));
 }
Esempio n. 6
0
 /// <summary>
 /// Determines whether a specfic FilteringRule value is in this FilteringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The FilteringRule value to locate in this FilteringRuleCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this FilteringRuleCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(FilteringRule value)
 {
     return(this.List.Contains(value));
 }
Esempio n. 7
0
 /// <summary>
 /// Adds an instance of type FilteringRule to the end of this FilteringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The FilteringRule to be added to the end of this FilteringRuleCollection.
 /// </param>
 public virtual void Add(FilteringRule value)
 {
     this.List.Add(value);
 }
Esempio n. 8
0
 /// <summary>
 /// Adds the elements of an array to the end of this FilteringRuleCollection.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the end of this FilteringRuleCollection.
 /// </param>
 public virtual void AddRange(FilteringRule[]items)
 {
     foreach (FilteringRule item in items)
     {
         this.List.Add(item);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the FilteringRuleCollection class, containing elements
 /// copied from an array.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the new FilteringRuleCollection.
 /// </param>
 public FilteringRuleCollection(FilteringRule[]items)
 {
     this.AddRange(items);
 }
Esempio n. 10
0
 /// <summary>
 /// Removes the first occurrence of a specific FilteringRule from this FilteringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The FilteringRule value to remove from this FilteringRuleCollection.
 /// </param>
 public virtual void Remove(FilteringRule value)
 {
     this.List.Remove(value);
 }
Esempio n. 11
0
 /// <summary>
 /// Inserts an element into the FilteringRuleCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the FilteringRule is to be inserted.
 /// </param>
 /// <param name="value">
 /// The FilteringRule to insert.
 /// </param>
 public virtual void Insert(int index, FilteringRule value)
 {
     this.List.Insert(index, value);
 }
Esempio n. 12
0
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this FilteringRuleCollection
 /// </summary>
 /// <param name="value">
 /// The FilteringRule value to locate in the FilteringRuleCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(FilteringRule value)
 {
     return this.List.IndexOf(value);
 }
Esempio n. 13
0
 /// <summary>
 /// Determines whether a specfic FilteringRule value is in this FilteringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The FilteringRule value to locate in this FilteringRuleCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this FilteringRuleCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(FilteringRule value)
 {
     return this.List.Contains(value);
 }
Esempio n. 14
0
 /// <summary>
 /// Adds an instance of type FilteringRule to the end of this FilteringRuleCollection.
 /// </summary>
 /// <param name="value">
 /// The FilteringRule to be added to the end of this FilteringRuleCollection.
 /// </param>
 public virtual void Add(FilteringRule value)
 {
     this.List.Add(value);
 }