Пример #1
0
        /// <summary>
        /// Renders the layout for the specified logging event by invoking layout renderers.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        /// <returns>The rendered layout.</returns>
        public string GetFormattedMessage(LogEventInfo logEvent)
        {
            string cachedValue = logEvent.GetCachedLayoutValue(this);
            if (cachedValue != null)
                return cachedValue;

            StringBuilder sb = new StringBuilder(_renderer.GetEstimatedBufferSize(logEvent));

            _renderer.Append(sb, logEvent);
            logEvent.AddCachedLayoutValue(this, sb.ToString());
            return sb.ToString();
        }
Пример #2
0
        /// <summary>
        /// Renders the layout for the specified logging event by invoking layout renderers.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        /// <returns>The rendered layout.</returns>
        public string GetFormattedMessage(LogEventInfo logEvent)
        {
            string cachedValue = logEvent.GetCachedLayoutValue(this);

            if (cachedValue != null)
            {
                return(cachedValue);
            }

            StringBuilder sb = new StringBuilder(_renderer.GetEstimatedBufferSize(logEvent));

            _renderer.Append(sb, logEvent);
            logEvent.AddCachedLayoutValue(this, sb.ToString());
            return(sb.ToString());
        }
Пример #3
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>
        public string GetFormattedMessage(LogEventInfo logEvent)
        {
            string cachedValue = logEvent.GetCachedLayoutValue(this);
            if (cachedValue != null)
                return cachedValue;

            StringBuilder sb = new StringBuilder();

            bool first = true;

            foreach (CsvColumn col in Columns)
            {
                if (!first)
                {
                    sb.Append(_actualColumnDelimiter);
                }

                first = false;

                bool useQuoting;
                string text = col.CompiledLayout.GetFormattedMessage(logEvent);

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

                    case CsvQuotingMode.All:
                        useQuoting = true;
                        break;

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

                if (useQuoting)
                    sb.Append(QuoteChar);

                if (useQuoting)
                    sb.Append(text.Replace(QuoteChar, _doubleQuoteChar));
                else
                    sb.Append(text);

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

            logEvent.AddCachedLayoutValue(this, sb.ToString());
            return sb.ToString();
        }
Пример #4
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>
        public string GetFormattedMessage(LogEventInfo logEvent)
        {
            string cachedValue = logEvent.GetCachedLayoutValue(this);

            if (cachedValue != null)
            {
                return(cachedValue);
            }

            StringBuilder sb = new StringBuilder();

            bool first = true;

            foreach (CsvColumn col in Columns)
            {
                if (!first)
                {
                    sb.Append(_actualColumnDelimiter);
                }

                first = false;

                bool   useQuoting;
                string text = col.CompiledLayout.GetFormattedMessage(logEvent);

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

                case CsvQuotingMode.All:
                    useQuoting = true;
                    break;

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

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

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

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

            logEvent.AddCachedLayoutValue(this, sb.ToString());
            return(sb.ToString());
        }