Ejemplo n.º 1
0
        /// <summary>
        /// Get the headers with the column names.
        /// </summary>
        /// <returns></returns>
        private void RenderHeader(StringBuilder sb)
        {
            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < this.Columns.Count; i++)
            {
                CsvColumn col = this.Columns[i];
                if (i != 0)
                {
                    sb.Append(this.actualColumnDelimiter);
                }

                bool   useQuoting;
                string text = col.Name;

                switch (this.Quoting)
                {
                case CsvQuotingMode.Nothing:
                    useQuoting = false;
                    break;

                case CsvQuotingMode.All:
                    useQuoting = true;
                    break;

                default:
                case CsvQuotingMode.Auto:
                    if (text.IndexOfAny(this.quotableCharacters) >= 0)
                    {
                        useQuoting = true;
                    }
                    else
                    {
                        useQuoting = false;
                    }

                    break;
                }

                if (useQuoting)
                {
                    sb.Append(this.QuoteChar);
                }

                if (useQuoting)
                {
                    sb.Append(text.Replace(this.QuoteChar, this.doubleQuoteChar));
                }
                else
                {
                    sb.Append(text);
                }

                if (useQuoting)
                {
                    sb.Append(this.QuoteChar);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the headers with the column names.
        /// </summary>
        /// <returns></returns>
        private void RenderHeader(StringBuilder sb)
        {
            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < this.Columns.Count; i++)
            {
                CsvColumn col  = this.Columns[i];
                string    text = col.Name;

                RenderCol(sb, i, text);
            }
        }
Ejemplo n.º 3
0
        private void RenderAllColumns(LogEventInfo logEvent, StringBuilder sb)
        {
            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < Columns.Count; i++)
            {
                CsvColumn col  = Columns[i];
                string    text = col.Layout.Render(logEvent);

                RenderCol(sb, i, text);
            }
        }
        /// <summary>
        /// Get the headers with the column names.
        /// </summary>
        /// <returns></returns>
        private void RenderHeader(StringBuilder sb)
        {
            LogEventInfo logEvent = LogEventInfo.CreateNullEvent();

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < Columns.Count; i++)
            {
                CsvColumn col          = Columns[i];
                var       columnLayout = new SimpleLayout(new LayoutRenderers.LayoutRenderer[] { new LayoutRenderers.LiteralLayoutRenderer(col.Name) }, col.Name, ConfigurationItemFactory.Default);
                columnLayout.Initialize(LoggingConfiguration);
                RenderColumnLayout(logEvent, columnLayout, col._quoting ?? Quoting, sb, i);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this CsvFileColumnCollection
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn value to locate in the CsvFileColumnCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(CsvColumn value)
 {
     return(this.List.IndexOf(value));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Determines whether a specfic CsvFileColumn value is in this CsvFileColumnCollection.
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn value to locate in this CsvFileColumnCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this CsvFileColumnCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(CsvColumn value)
 {
     return(this.List.Contains(value));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds an instance of type CsvFileColumn to the end of this CsvFileColumnCollection.
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn to be added to the end of this CsvFileColumnCollection.
 /// </param>
 public virtual void Add(CsvColumn value)
 {
     this.List.Add(value);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Formats the log event for write.
        /// </summary>
        /// <param name="logEvent">The log event to be formatted.</param>
        /// <returns>A string representation of the log event.</returns>
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            string cachedValue;

            if (logEvent.TryGetCachedLayoutValue(this, out cachedValue))
            {
                return(cachedValue);
            }

            var sb = new StringBuilder();

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < this.Columns.Count; i++)
            {
                CsvColumn col = this.Columns[i];
                if (i != 0)
                {
                    sb.Append(this.actualColumnDelimiter);
                }

                bool   useQuoting;
                string text = col.Layout.Render(logEvent);

                switch (this.Quoting)
                {
                case CsvQuotingMode.Nothing:
                    useQuoting = false;
                    break;

                case CsvQuotingMode.All:
                    useQuoting = true;
                    break;

                default:
                case CsvQuotingMode.Auto:
                    if (text.IndexOfAny(this.quotableCharacters) >= 0)
                    {
                        useQuoting = true;
                    }
                    else
                    {
                        useQuoting = false;
                    }

                    break;
                }

                if (useQuoting)
                {
                    sb.Append(this.QuoteChar);
                }

                if (useQuoting)
                {
                    sb.Append(text.Replace(this.QuoteChar, this.doubleQuoteChar));
                }
                else
                {
                    sb.Append(text);
                }

                if (useQuoting)
                {
                    sb.Append(this.QuoteChar);
                }
            }

            return(logEvent.AddCachedLayoutValue(this, sb.ToString()));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Determines whether a specfic CsvFileColumn value is in this CsvFileColumnCollection.
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn value to locate in this CsvFileColumnCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this CsvFileColumnCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(CsvColumn value)
 {
     return this.List.Contains(value);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Adds the elements of an array to the end of this CsvFileColumnCollection.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the end of this CsvFileColumnCollection.
 /// </param>
 public virtual void AddRange(CsvColumn[]items)
 {
     foreach (CsvColumn item in items)
     {
         this.List.Add(item);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the CsvFileColumnCollection class, containing elements
 /// copied from an array.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the new CsvFileColumnCollection.
 /// </param>
 public CsvColumnCollection(CsvColumn[]items)
 {
     this.AddRange(items);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Removes the first occurrence of a specific CsvFileColumn from this CsvFileColumnCollection.
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn value to remove from this CsvFileColumnCollection.
 /// </param>
 public virtual void Remove(CsvColumn value)
 {
     this.List.Remove(value);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Inserts an element into the CsvFileColumnCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the CsvFileColumn is to be inserted.
 /// </param>
 /// <param name="value">
 /// The CsvFileColumn to insert.
 /// </param>
 public virtual void Insert(int index, CsvColumn value)
 {
     this.List.Insert(index, value);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this CsvFileColumnCollection
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn value to locate in the CsvFileColumnCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(CsvColumn value)
 {
     return this.List.IndexOf(value);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Inserts an element into the CsvFileColumnCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the CsvFileColumn is to be inserted.
 /// </param>
 /// <param name="value">
 /// The CsvFileColumn to insert.
 /// </param>
 public virtual void Insert(int index, CsvColumn value)
 {
     this.List.Insert(index, value);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Removes the first occurrence of a specific CsvFileColumn from this CsvFileColumnCollection.
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn value to remove from this CsvFileColumnCollection.
 /// </param>
 public virtual void Remove(CsvColumn value)
 {
     this.List.Remove(value);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Adds an instance of type CsvFileColumn to the end of this CsvFileColumnCollection.
 /// </summary>
 /// <param name="value">
 /// The CsvFileColumn to be added to the end of this CsvFileColumnCollection.
 /// </param>
 public virtual void Add(CsvColumn value)
 {
     this.List.Add(value);
 }