本文整理匯總了C#中NLog.LogEventInfo.GetCachedLayoutValue方法的典型用法代碼示例。如果您正苦於以下問題:C# LogEventInfo.GetCachedLayoutValue方法的具體用法?C# LogEventInfo.GetCachedLayoutValue怎麽用?C# LogEventInfo.GetCachedLayoutValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NLog.LogEventInfo
的用法示例。
在下文中一共展示了LogEventInfo.GetCachedLayoutValue方法的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;
}