/// <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); RenderAllRenderers(logEvent, builder); if (builder.Length > this.maxRenderedLength) { this.maxRenderedLength = builder.Length; } return(logEvent.AddCachedLayoutValue(this, builder.ToString())); }
/// <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); }
/// <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)); }
/// <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())); }
/// <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))); }
/// <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); 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); }
private void Render(StringBuilder target, LogEventInfo logEvent) { if (!this.IsThreadAgnostic) { string cachedValue; if (logEvent.TryGetCachedLayoutValue(this, out cachedValue)) { target.Append(cachedValue); return; } } StringBuilder intermediate = target; if (target.Length != 0) { int initialSize = this.maxRenderedLength; if (initialSize > MaxInitialRenderBufferLength) { initialSize = MaxInitialRenderBufferLength; } if (this.LoggingConfiguration.PoolingEnabled()) { intermediate = this.LoggingConfiguration.PoolFactory.Get <StringBuilderPool, StringBuilder>().Get(); } else { intermediate = new StringBuilder(initialSize); } } this.RenderAllRenderers(logEvent, intermediate); if (!this.IsThreadAgnostic) { logEvent.AddCachedLayoutValue(this, intermediate.ToString()); } if (intermediate.Length > this.maxRenderedLength) { this.maxRenderedLength = target.Length; } if (target != intermediate) { target.Append(intermediate); this.LoggingConfiguration.PutBack(intermediate); } }
/// <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(); }
/// <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(); RenderAllColumns(logEvent, sb); return(logEvent.AddCachedLayoutValue(this, sb.ToString())); }
/// <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); } var sb = new StringBuilder(); this.parent.RenderHeader(sb); return(logEvent.AddCachedLayoutValue(this, sb.ToString())); }
/// <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()); }
/// <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; }
/// <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())); }
/// <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()); }
/// <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(); bool first = true; foreach (CsvColumn col in this.Columns) { if (!first) { sb.Append(this.actualColumnDelimiter); } first = false; 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()); }
/// <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; }
/// <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()); }
/// <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()); }
/// <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(); var first = true; foreach (var col in Columns) { if (!first) { sb.Append(actualColumnDelimiter); } first = false; bool useQuoting; var text = col.Layout.Render(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); } } return(logEvent.AddCachedLayoutValue(this, sb.ToString())); }
/// <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(); }
/// <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; }