本文整理汇总了C#中NLog.Layouts.Layout.Render方法的典型用法代码示例。如果您正苦于以下问题:C# Layout.Render方法的具体用法?C# Layout.Render怎么用?C# Layout.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog.Layouts.Layout
的用法示例。
在下文中一共展示了Layout.Render方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessageInner
public static string GetMessageInner(bool useJSON, Layout layout, LogEventInfo info)
{
if (!useJSON)
return layout.Render(info);
var logLine = new LogLine
{
TimeStampISO8601 = info.TimeStamp.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture),
Message = info.FormattedMessage,
Level = info.Level.Name,
Type = "amqp",
Source = new Uri(string.Format("nlog://{0}/{1}", HostName, info.LoggerName))
};
logLine.AddField("exception", info.Exception);
if (info.Properties.Count > 0 && info.Properties.ContainsKey("fields"))
foreach (var kv in (IEnumerable<KeyValuePair<string, object>>) info.Properties["fields"])
logLine.AddField(kv.Key, kv.Value);
if (info.Properties.Count > 0 && info.Properties.ContainsKey("tags"))
foreach (var tag in (IEnumerable<string>) info.Properties["tags"])
logLine.AddTag(tag);
logLine.EnsureADT();
return JsonConvert.SerializeObject(logLine);
}
示例2: GetMessageInner
public static string GetMessageInner(bool useJSON, bool useLayoutAsMessage, Layout layout, LogEventInfo info, IList<Field> fields)
{
if (!useJSON)
return layout.Render(info);
var logLine = new LogLine
{
TimeStampISO8601 = info.TimeStamp.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture),
Message = useLayoutAsMessage ? layout.Render(info) : info.FormattedMessage,
Level = info.Level.Name,
Type = "amqp",
Source = new Uri(string.Format("nlog://{0}/{1}", HostName, info.LoggerName))
};
logLine.AddField("exception", info.Exception);
if (info.Properties.Count > 0 && info.Properties.ContainsKey("fields"))
foreach (var kv in (IEnumerable<KeyValuePair<string, object>>) info.Properties["fields"])
logLine.AddField(kv.Key, kv.Value);
if (info.Properties.Count > 0 && info.Properties.ContainsKey("tags"))
foreach (var tag in (IEnumerable<string>) info.Properties["tags"])
logLine.AddTag(tag);
foreach (var propertyPair in info.Properties)
{
var key = propertyPair.Key as string;
if (key == null || key == "tags" || key == "fields")
continue;
logLine.AddField((string) propertyPair.Key, propertyPair.Value);
}
if (fields != null)
foreach (Field field in fields)
if (logLine.Fields == null || !logLine.Fields.Any(x => x.Key == field.Name))
logLine.AddField(field.Name, field.Layout.Render(info));
logLine.EnsureADT();
return JsonConvert.SerializeObject(logLine);
}
示例3: AddAddresses
/// <summary>
/// Render <paramref name="layout"/> and add the addresses to <paramref name="mailAddressCollection"/>
/// </summary>
/// <param name="mailAddressCollection">Addresses appended to this list</param>
/// <param name="layout">layout with addresses, ; separated</param>
/// <param name="logEvent">event for rendering the <paramref name="layout"/></param>
/// <returns>added a address?</returns>
private static bool AddAddresses(MailAddressCollection mailAddressCollection, Layout layout, LogEventInfo logEvent)
{
var added = false;
if (layout != null)
{
foreach (string mail in layout.Render(logEvent).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
mailAddressCollection.Add(mail);
added = true;
}
}
return added;
}
示例4: AppendLayout
/// <summary>
/// Append rendered layout to the stringbuilder
/// </summary>
/// <param name="sb">append to this</param>
/// <param name="logEvent">event for rendering <paramref name="layout"/></param>
/// <param name="layout">append if not <c>null</c></param>
private static void AppendLayout(StringBuilder sb, LogEventInfo logEvent, Layout layout)
{
sb.Append("|");
if (layout != null)
sb.Append(layout.Render(logEvent));
}
示例5: ExecTest
/// <summary>
/// set in Session and test
/// </summary>
/// <param name="key">set with this key</param>
/// <param name="value">set this value</param>
/// <param name="expected">expected</param>
/// <param name="appSettingLayoutRenderer"></param>
/// <remarks>IRenderable is internal</remarks>
private void ExecTest(string key, object value, object expected, Layout appSettingLayoutRenderer)
{
Session[key] = value;
var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());
Assert.Equal(expected, rendered);
}
示例6: AssertLayoutRendererOutput
/// <summary>
/// Render layout <paramref name="layout"/> with <paramref name="logEventInfo"/> and compare result with <paramref name="expected"/>.
/// </summary>
protected static void AssertLayoutRendererOutput(Layout layout, LogEventInfo logEventInfo, string expected)
{
layout.Initialize(null);
string actual = layout.Render(logEventInfo);
layout.Close();
Assert.Equal(expected, actual);
}
示例7: AssertLayoutRendererOutput
protected void AssertLayoutRendererOutput(Layout l, string expected)
{
l.Initialize(null);
string actual = l.Render(LogEventInfo.Create(LogLevel.Info, "loggername", "message"));
l.Close();
Assert.AreEqual(expected, actual);
}
示例8: BuildLogEntries
public string[] BuildLogEntries(LogEventInfo logEvent, Layout layout)
{
var originalLogEntry = layout.Render(logEvent);
return splitOnNewLinePolicy.IsApplicable() ? splitOnNewLinePolicy.Apply(originalLogEntry) : new[] { originalLogEntry };
}