本文整理汇总了C#中NLog.LogEventInfo.AddCachedLayoutValue方法的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo.AddCachedLayoutValue方法的具体用法?C# LogEventInfo.AddCachedLayoutValue怎么用?C# LogEventInfo.AddCachedLayoutValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog.LogEventInfo
的用法示例。
在下文中一共展示了LogEventInfo.AddCachedLayoutValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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>
public string GetFormattedMessage(LogEventInfo logEvent)
{
if (_fixedText != null)
return _fixedText;
string cachedValue = logEvent.GetCachedLayoutValue(this);
if (cachedValue != null)
return cachedValue;
int size = 0;
for (int i = 0; i < _renderers.Length; ++i)
{
LayoutRenderer app = _renderers[i];
try
{
int ebs = app.GetEstimatedBufferSize(logEvent);
size += ebs;
}
catch (Exception ex)
{
if (InternalLogger.IsWarnEnabled)
{
InternalLogger.Warn("Exception in {0}.GetEstimatedBufferSize(): {1}.", app.GetType().FullName, ex);
}
}
}
StringBuilder builder = new StringBuilder(size);
for (int i = 0; i < _renderers.Length; ++i)
{
LayoutRenderer app = _renderers[i];
try
{
app.Append(builder, logEvent);
}
catch (Exception ex)
{
if (InternalLogger.IsWarnEnabled)
{
InternalLogger.Warn("Exception in {0}.Append(): {1}.", app.GetType().FullName, ex);
}
}
}
string value = builder.ToString();
logEvent.AddCachedLayoutValue(this, value);
return value;
}