本文整理汇总了C#中NLog.Layouts.Layout类的典型用法代码示例。如果您正苦于以下问题:C# Layout类的具体用法?C# Layout怎么用?C# Layout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Layout类属于NLog.Layouts命名空间,在下文中一共展示了Layout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: AssertMessageAndLogLevelForTruncatedMessages
private void AssertMessageAndLogLevelForTruncatedMessages(LogLevel loglevel, EventLogEntryType expectedEventLogEntryType, string expectedMessage, Layout entryTypeLayout)
{
const int expectedEntryCount = 1;
var eventRecords = Write(loglevel, expectedEventLogEntryType, expectedMessage, entryTypeLayout, EventLogTargetOverflowAction.Truncate).ToList();
Assert.Equal(expectedEntryCount, eventRecords.Count);
AssertWrittenMessage(eventRecords, expectedMessage);
}
示例3: Rfc3164
public Rfc3164(Facility facility, Rfc3164Config rfc3164Config, EnforcementConfig enforcementConfig) : base(facility, enforcementConfig)
{
hostnamePolicySet = new PlainHostnamePolicySet(enforcementConfig);
tagPolicySet = new TagPolicySet(enforcementConfig);
plainContentPolicySet = new PlainContentPolicySet(enforcementConfig);
asciiMessagePolicy = new AsciiMessagePolicy(enforcementConfig);
hostnameLayout = rfc3164Config.Hostname;
tagLayout = rfc3164Config.Tag;
}
示例4: AsyncLogger
public AsyncLogger(Layout loggingLayout, EnforcementConfig enforcementConfig, MessageBuilder messageBuilder, MessageTransmitterConfig messageTransmitterConfig)
{
layout = loggingLayout;
cts = new CancellationTokenSource();
token = cts.Token;
throttling = Throttling.FromConfig(enforcementConfig.Throttling);
queue = NewBlockingCollection();
buffer = new ByteArray(enforcementConfig.TruncateMessageTo);
messageTransmitter = MessageTransmitter.FromConfig(messageTransmitterConfig);
Task.Factory.StartNew(() => ProcessQueueAsync(messageBuilder));
}
示例5: FilePathLayout
//TODO onInit maken
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
public FilePathLayout(Layout layout, bool cleanupInvalidChars, FilePathKind filePathKind)
{
_layout = layout;
_filePathKind = filePathKind;
_cleanupInvalidChars = cleanupInvalidChars;
if (_layout == null)
{
_filePathKind = FilePathKind.Unknown;
return;
}
//do we have to the the layout?
if (cleanupInvalidChars || _filePathKind == FilePathKind.Unknown)
{
//check if fixed
var pathLayout2 = layout as SimpleLayout;
if (pathLayout2 != null)
{
var isFixedText = pathLayout2.IsFixedText;
if (isFixedText)
{
cleanedFixedResult = pathLayout2.FixedText;
if (cleanupInvalidChars)
{
//clean first
cleanedFixedResult = CleanupInvalidFilePath(cleanedFixedResult);
}
}
//detect absolute
if (_filePathKind == FilePathKind.Unknown)
{
_filePathKind = DetectFilePathKind(pathLayout2);
}
}
else
{
_filePathKind = FilePathKind.Unknown;
}
}
#if !SILVERLIGHT
if (_filePathKind == FilePathKind.Relative)
{
_baseDir = AppDomainWrapper.CurrentDomain.BaseDirectory;
}
#endif
}
示例6: Rfc5424
public Rfc5424(Facility facility, Rfc5424Config rfc5424Config, EnforcementConfig enforcementConfig) : base(facility, enforcementConfig)
{
version = DefaultVersion;
hostnameLayout = rfc5424Config.Hostname;
appNameLayout = rfc5424Config.AppName;
procIdLayout = NilValue;
msgIdLayout = NilValue;
structuredData = new StructuredData(rfc5424Config.StructuredData, enforcementConfig);
disableBom = rfc5424Config.DisableBom;
hostnamePolicySet = new FqdnHostnamePolicySet(enforcementConfig, rfc5424Config.DefaultHostname);
appNamePolicySet = new AppNamePolicySet(enforcementConfig, rfc5424Config.DefaultAppName);
procIdPolicySet = new ProcIdPolicySet(enforcementConfig);
msgIdPolicySet = new MsgIdPolicySet(enforcementConfig);
utf8MessagePolicy = new Utf8MessagePolicy(enforcementConfig);
}
示例7: GetMessageInner
public static string GetMessageInner(bool useJSON, 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 = 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);
}
示例8: 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));
}
示例9: Write
private static IEnumerable<EventRecord> Write(LogLevel logLevel, EventLogEntryType expectedEventLogEntryType, string logMessage, Layout entryType = null, EventLogTargetOverflowAction overflowAction = EventLogTargetOverflowAction.Truncate, int maxMessageLength = 16384)
{
var target = CreateEventLogTarget(entryType, "NLog.UnitTests" + Guid.NewGuid().ToString("N"), overflowAction, maxMessageLength);
SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);
var logger = LogManager.GetLogger("WriteEventLogEntry");
logger.Log(logLevel, logMessage);
var eventLog = new EventLog(target.Log);
var entries = GetEventRecords(eventLog.Log).ToList();
var expectedSource = target.GetFixedSource();
var filteredEntries = entries.Where(entry =>
entry.ProviderName == expectedSource &&
HasEntryType(entry, expectedEventLogEntryType)
);
if (overflowAction == EventLogTargetOverflowAction.Discard && logMessage.Length > maxMessageLength)
{
Assert.False(filteredEntries.Any(), string.Format("No message is expected. But {0} message(s) found entry of type '{1}' from source '{2}'.", filteredEntries.Count(), expectedEventLogEntryType, expectedSource));
}
else
{
Assert.True(filteredEntries.Any(), string.Format("Failed to find entry of type '{0}' from source '{1}'", expectedEventLogEntryType, expectedSource));
}
return filteredEntries;
}
示例10: CsvColumn
/// <summary>
/// Initializes a new instance of the <see cref="CsvColumn" /> class.
/// </summary>
/// <param name="name">The name of the column.</param>
/// <param name="layout">The layout of the column.</param>
public CsvColumn(string name, Layout layout)
{
this.Name = name;
this.Layout = layout;
}
示例11: 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);
}
示例12: MethodCallParameter
/// <summary>
/// Initializes a new instance of the <see cref="MethodCallParameter" /> class.
/// </summary>
/// <param name="parameterName">Name of the parameter.</param>
/// <param name="layout">The layout.</param>
public MethodCallParameter(string parameterName, Layout layout)
{
this.Type = typeof(string);
this.Name = parameterName;
this.Layout = layout;
}
示例13: ElastisearchParameterInfo
public ElastisearchParameterInfo(string name, Layout layout)
{
this.Name = name;
this.Layout = layout;
}
示例14: JsonAttribute
/// <summary>
/// Initializes a new instance of the <see cref="JsonAttribute" /> class.
/// </summary>
/// <param name="name">The name of the attribute.</param>
/// <param name="layout">The layout of the attribute's value.</param>
public JsonAttribute(string name, Layout layout)
{
this.Name = name;
this.Layout = layout;
}
示例15: DatabaseParameterInfo
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseParameterInfo" /> class.
/// </summary>
/// <param name="parameterName">Name of the parameter.</param>
/// <param name="parameterLayout">The parameter layout.</param>
public DatabaseParameterInfo(string parameterName, Layout parameterLayout)
{
this.Name = parameterName;
this.Layout = parameterLayout;
}