本文整理汇总了C#中LogEntry.AttachObject方法的典型用法代码示例。如果您正苦于以下问题:C# LogEntry.AttachObject方法的具体用法?C# LogEntry.AttachObject怎么用?C# LogEntry.AttachObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEntry
的用法示例。
在下文中一共展示了LogEntry.AttachObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanDeserializeComplexEntry
public static void CanDeserializeComplexEntry()
{
var entry = new LogEntry(LogLevel.Debug, "DEBUG", new Json[] { "arg" });
entry.Tag("tag");
entry.AttachObject("two", 2);
var json = JsonConvert.SerializeObject(entry);
var reconstructedEntry = JsonConvert.DeserializeObject<LogEntry>(json);
Assert.AreEqual(entry, reconstructedEntry);
}
示例2: CanSerializeComplexEntryToJson
public static void CanSerializeComplexEntryToJson()
{
var entry = new LogEntry(LogLevel.Debug, "DEBUG", new Json[] { "arg" });
entry.Tag("tag");
entry.AttachObject("two", 2);
var dt = entry.DateTime;
var dtstr = dt.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFZ");
var expectedJson = String.Format("{{\"DateTime\":\"{0}\",\"LogLevel\":{1},\"Message\":\"{2}\",\"TagList\":[\"tag\"],\"Parameters\":{{\"0\":\"arg\"}},\"Attachments\":{{\"two\":2}}}}", dtstr, (int)LogLevel.Debug, "DEBUG");
var json = JsonConvert.SerializeObject(entry);
Assert.AreEqual(expectedJson, json);
}
示例3: Log
public override void Log(LogEntry logEntry)
{
foreach (var tag in TagList)
{
logEntry.Tag(tag);
}
foreach (var kv in AttachObjects)
{
var key = kv.Key;
var obj = kv.Value;
logEntry.AttachObject(key, obj);
}
}