当前位置: 首页>>代码示例>>C#>>正文


C# LogEventInfo.TryGetCachedLayoutValue方法代码示例

本文整理汇总了C#中LogEventInfo.TryGetCachedLayoutValue方法的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo.TryGetCachedLayoutValue方法的具体用法?C# LogEventInfo.TryGetCachedLayoutValue怎么用?C# LogEventInfo.TryGetCachedLayoutValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogEventInfo的用法示例。


在下文中一共展示了LogEventInfo.TryGetCachedLayoutValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFormattedMessage

        /// <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>
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            string cachedValue;

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

            return logEvent.AddCachedLayoutValue(this, this.Renderer.Render(logEvent));
        }
开发者ID:rameshr,项目名称:NLog,代码行数:16,代码来源:Log4JXmlEventLayout.cs

示例2: GetFormattedMessage

        /// <summary>
        /// Renders the layout for the specified logging event by invoking layout renderers
        /// that make up the event.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        /// <returns>The rendered layout.</returns>
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            if (this.fixedText != null)
            {
                return this.fixedText;
            }

            string cachedValue;

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

            int initialSize = this.maxRenderedLength;
            if (initialSize > MaxInitialRenderBufferLength)
            {
                initialSize = MaxInitialRenderBufferLength;
            }

            var builder = new StringBuilder(initialSize);

            foreach (LayoutRenderer renderer in this.Renderers)
            {
                try
                {
                    renderer.Render(builder, logEvent);
                }
                catch (Exception exception)
                {
                    if (exception.MustBeRethrown())
                    {
                        throw;
                    }

                    if (InternalLogger.IsWarnEnabled)
                    {
                        InternalLogger.Warn("Exception in {0}.Append(): {1}.", renderer.GetType().FullName, exception);
                    }
                }
            }

            if (builder.Length > this.maxRenderedLength)
            {
                this.maxRenderedLength = builder.Length;
            }

            string value = builder.ToString();
            logEvent.AddCachedLayoutValue(this, value);
            return value;
        }
开发者ID:semirs,项目名称:CellAO,代码行数:57,代码来源:SimpleLayout.cs

示例3: GetFormattedMessage

            /// <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>
            protected override string GetFormattedMessage(LogEventInfo logEvent)
            {
                string cached;

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

                return logEvent.AddCachedLayoutValue(this, this.parent.GetHeader());
            }
开发者ID:clapette,项目名称:BehaviorIsManaged,代码行数:16,代码来源:CsvLayout.cs

示例4: GetFormattedMessage

        /// <summary>
        /// Renders the layout for the specified logging event by invoking layout renderers
        /// that make up the event.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        /// <returns>The rendered layout.</returns>
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            if (IsFixedText)
            {
                return this.fixedText;
            }

            string cachedValue;

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

            int initialSize = this.maxRenderedLength;
            if (initialSize > MaxInitialRenderBufferLength)
            {
                initialSize = MaxInitialRenderBufferLength;
            }

            var builder = new StringBuilder(initialSize);

            //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.Renderers.Count; i++)
            {
                LayoutRenderer renderer = this.Renderers[i];
                try
                {
                    renderer.Render(builder, logEvent);
                }
                catch (Exception exception)
                {
                    //also check IsErrorEnabled, otherwise 'MustBeRethrown' writes it to Error

                    //check for performance
                    if (InternalLogger.IsWarnEnabled || InternalLogger.IsErrorEnabled)
                    {
                        InternalLogger.Warn(exception, "Exception in '{0}.Append()'", renderer.GetType().FullName);
                    }

                    if (exception.MustBeRethrown())
                    {
                        throw;
                    }
                }
            }

            if (builder.Length > this.maxRenderedLength)
            {
                this.maxRenderedLength = builder.Length;
            }

            string value = builder.ToString();
            logEvent.AddCachedLayoutValue(this, value);
            return value;
        }
开发者ID:daniefer,项目名称:NLog,代码行数:63,代码来源:SimpleLayout.cs

示例5: GetFormattedMessage

        /// <summary>
        /// Renders the layout for the specified logging event by invoking layout renderers
        /// that make up the event.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        /// <returns>The rendered layout.</returns>
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            if(Renderers == null)
                throw new InvalidOperationException("required run CreateParameters method");

            if (_fixedText != null)
                return _fixedText;

            string cachedValue;

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

            int initialSize = _maxRenderedLength;
            if (initialSize > MaxInitialRenderBufferLength)
                initialSize = MaxInitialRenderBufferLength;

            var builder = new StringBuilder(initialSize);

            foreach (LayoutRenderer renderer in Renderers)
            {
                try
                {
                    renderer.Render(builder, logEvent);
                }
                catch (Exception exception)
                {
                    if (exception.MustBeRethrown())
                        throw;

                    if (InternalLogger.IsWarnEnabled)
                        InternalLogger.Warn("Exception in {0}.Append(): {1}.", renderer.GetType().FullName, exception);
                }
            }

            if (builder.Length > _maxRenderedLength)
                _maxRenderedLength = builder.Length;

            string value = builder.ToString();
            logEvent.AddCachedLayoutValue(this, value);
            return value;
        }
开发者ID:ExM,项目名称:NLog,代码行数:48,代码来源:SimpleLayout.cs

示例6: GetFormattedMessage

        /// <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());
        }
开发者ID:CharlieBP,项目名称:NLog,代码行数:75,代码来源:CsvLayout.cs


注:本文中的LogEventInfo.TryGetCachedLayoutValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。