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


C# LogMessage.ToString方法代码示例

本文整理汇总了C#中LogMessage.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LogMessage.ToString方法的具体用法?C# LogMessage.ToString怎么用?C# LogMessage.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogMessage的用法示例。


在下文中一共展示了LogMessage.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ItFormatsTimestampsAsExpected

 public void ItFormatsTimestampsAsExpected()
 {
     var logMessage = new LogMessage
         {
             Message = "Hello, world!",
         };
         var jsonMessage = logMessage.ToString();
         var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonMessage);
         var regex = new Regex(@"\d+\.\d{9}");
         StringAssert.Matches(dictionary["timestamp"], regex);
 }
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:11,代码来源:LoggerTests.cs

示例2: ItConvertsFieldsToUnderscorized

 public void ItConvertsFieldsToUnderscorized()
 {
     var logMessage = new LogMessage
         {
             Message = "Hello, world!",
             LogLevel = LogLevel.FATAL
         };
         var jsonMessage = logMessage.ToString();
         var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonMessage);
         Assert.AreEqual("Hello, world!", dictionary["message"]);
         Assert.AreEqual(LogLevel.FATAL.ToString("D"), dictionary["log_level"]);
 }
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:12,代码来源:LoggerTests.cs

示例3: LogMessage

        private void LogMessage(LogMessage logMessage)
        {

            var logTask = new Task(() =>
            {
                try
                {
                    Logger.Debug(logMessage.ToString());
                }
                catch (Exception ex)
                {
                    if (ex is AggregateException)
                        ex = ex.InnerException;

                    Logger.Error("Erro ao gerar log da resposta: " + ex.Message, ex);
                }
            });
            logTask.Start();

        }
开发者ID:CentauroTech,项目名称:CentauroTech.Utils.WcfLogger,代码行数:20,代码来源:LogMessageInspector.cs

示例4: GetFormatted

		/// <summary>
        ///     Возвращет форматированный текст из представления сообщения <see cref="LogMessage"/>
		/// </summary>
        /// <param name="message">Представление сообщения <see cref="LogMessage"/></param>
        /// <returns>Форматированная строка сообщения</returns>
		protected virtual string GetFormatted(LogMessage message) {
			string text;
			if (!string.IsNullOrEmpty(CustomFormat)) {
				text = Regex.Replace(CustomFormat, @"\$\{(\w+)\}", m =>
					{
						var propName = m.Groups[1].Value;
						var prop = message.GetType().GetProperty(propName);
						if (null != prop) {
							var val = prop.GetValue(message, null);
							if (null == val) {
								return "";
							}
							if (val is DateTime) {
								return ((DateTime) val).ToString("yyyy-MM-dd HH:mm:ss");
							}
							return val.ToString();
						}
						return "";
					});
			}
			else {
				text = message.ToString();
			}
			return text;
		}
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:30,代码来源:BaseLogWriter.cs

示例5: LogFailSafe

		/// <summary>
		/// 	Fail safe UserLog gate to write internal exception without main logging context, but with max guarantee of regestering
		/// 	synchronous
		/// </summary>
		public void LogFailSafe(LogMessage message) {
			if (null == message) {
				return;
			}
			if (string.IsNullOrEmpty(message.Name)) {
				message.Name = "FAILSAFE";
			}
			try {
				StreamWriter wr = null;
				for (var i = 0; i < 100; i++) {
					try {
						wr = new StreamWriter(Path.Combine(EnvironmentInfo.RootDirectory, "failsafelog" + i + ".txt"), true, Encoding.UTF8);
						break;
					}
// ReSharper disable EmptyGeneralCatchClause
					catch (Exception) {}
// ReSharper restore EmptyGeneralCatchClause
				}
				if (null == wr) {
					var tmpfile = Path.GetTempFileName() + ".failsafelog." +
					              DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss", CultureInfo.InvariantCulture) + ".txt";
					wr = new StreamWriter(tmpfile, true, Encoding.UTF8);
				}
				using (wr) {
					wr.WriteLine(message.ToString());
					wr.Flush();
				}
			}
			catch (Exception ex) {
				throw new LogException("even safe mode fails to be executed", ex);
			}
		}
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:36,代码来源:DefaultLogManager.cs


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