本文整理汇总了C#中LogEventInfo.AddCachedLayoutValue方法的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo.AddCachedLayoutValue方法的具体用法?C# LogEventInfo.AddCachedLayoutValue怎么用?C# LogEventInfo.AddCachedLayoutValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEventInfo
的用法示例。
在下文中一共展示了LogEventInfo.AddCachedLayoutValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例2: 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>
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: 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>
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: 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;
}
示例5: 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());
}
示例6: 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;
}
示例7: 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;
}
示例8: 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());
}