本文整理汇总了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();
}
示例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();
}
示例3: Render
private string Render(LoggingEvent loggingEvent, ILayout layout)
{
var m = new StringWriter();
layout.Format(m, loggingEvent);
return m.ToString();
}