当前位置: 首页>>代码示例>>C#>>正文


C# Layout.Render方法代码示例

本文整理汇总了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);
		}
开发者ID:nslowes,项目名称:NLog.RabbitMQ,代码行数:28,代码来源:MessageFormatter.cs

示例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);
		}
开发者ID:schillerhiqs,项目名称:NLog.RabbitMQ,代码行数:42,代码来源:MessageFormatter.cs

示例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;
        }
开发者ID:xiaopohou,项目名称:NLog,代码行数:21,代码来源:MailTarget.cs

示例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));
 }
开发者ID:xiaopohou,项目名称:NLog,代码行数:12,代码来源:MailTarget.cs

示例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);
        }
开发者ID:petemounce,项目名称:NLog.Web,代码行数:16,代码来源:AspNetSessionValueLayoutRendererTests.cs

示例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);
 }
开发者ID:rosj91,项目名称:NLog,代码行数:10,代码来源:NLogTestBase.cs

示例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);
 }
开发者ID:Loopt,项目名称:NLog,代码行数:7,代码来源:NLogTestBase.cs

示例8: BuildLogEntries

 public string[] BuildLogEntries(LogEventInfo logEvent, Layout layout)
 {
     var originalLogEntry = layout.Render(logEvent);
     return splitOnNewLinePolicy.IsApplicable() ? splitOnNewLinePolicy.Apply(originalLogEntry) : new[] { originalLogEntry };
 }
开发者ID:graffen,项目名称:NLog.Targets.Syslog,代码行数:5,代码来源:MessageBuilder.cs


注:本文中的NLog.Layouts.Layout.Render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。