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


C# ILayout.Format方法代码示例

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


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

示例1: GetXmlString

        internal static string GetXmlString(this LoggingEvent loggingEvent, ILayout layout = null)
        {
            string message = loggingEvent.RenderedMessage + Environment.NewLine + loggingEvent.GetExceptionString();
            if (layout != null)
            {
                using (var w = new StringWriter())
                {
                    layout.Format(w, loggingEvent);
                    message = w.ToString();
                }
            }

            var logXml = new XElement(
                "LogEntry",
                new XElement("UserName", loggingEvent.UserName),
                new XElement("TimeStamp",
                    loggingEvent.TimeStamp.ToString(CultureInfo.InvariantCulture)),
                new XElement("ThreadName", loggingEvent.ThreadName),
                new XElement("LoggerName", loggingEvent.LoggerName),
                new XElement("Level", loggingEvent.Level),
                new XElement("Identity", loggingEvent.Identity),
                new XElement("Domain", loggingEvent.Domain),
                new XElement("CreatedOn", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)),
                new XElement("RenderedMessage", message),
                new XElement("Location", loggingEvent.LocationInformation.FullInfo)
                );

            if (loggingEvent.Properties != null && loggingEvent.Properties.Count > 0)
            {
                var props = loggingEvent.Properties;
                if (props.Contains("AddPropertiesToXml"))
                {
                    foreach (var k in props.GetKeys())
                    {
                        var key = k.Replace(":", "_")
                                   .Replace("@", "_")
                                   .Replace(".", "_");
                        logXml.Add(new XElement(key, props[k].ToString()));
                    }
                }
            }

            if (loggingEvent.ExceptionObject != null)
            {
                logXml.Add(new XElement("Exception", loggingEvent.ExceptionObject.ToString()));
            }

            return logXml.ToString();
        }
开发者ID:stemarie,项目名称:log4net.Azure,代码行数:49,代码来源:LoggingEventExtensions.cs

示例2: AzureLayoutLoggingEventEntity

        public AzureLayoutLoggingEventEntity(LoggingEvent e, PartitionKeyTypeEnum partitionKeyType, ILayout layout)
        {
            Level = e.Level.ToString();
            Message = e.RenderedMessage + Environment.NewLine + e.GetExceptionString();
            ThreadName = e.ThreadName;
            EventTimeStamp = e.TimeStamp;
            using (var w = new StringWriter())
            {
                layout.Format(w, e);
                Message = w.ToString();
            }

            PartitionKey = e.MakePartitionKey(partitionKeyType);
            RowKey = e.MakeRowKey();
        }
开发者ID:Thumann,项目名称:log4net.Azure,代码行数:15,代码来源:AzureLayoutLoggingEventEntity.cs

示例3: Render

 private string Render(LoggingEvent loggingEvent, ILayout layout)
 {
     var m = new StringWriter();
     layout.Format(m, loggingEvent);
     return m.ToString();
 }
开发者ID:lcorneliussen,项目名称:xpatch,代码行数:6,代码来源:XPatchConsoleAppender.cs


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