當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。