本文整理汇总了C#中Newtonsoft.Json.Serialization.MemoryTraceWriter.GetTraceMessages方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryTraceWriter.GetTraceMessages方法的具体用法?C# MemoryTraceWriter.GetTraceMessages怎么用?C# MemoryTraceWriter.GetTraceMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Serialization.MemoryTraceWriter
的用法示例。
在下文中一共展示了MemoryTraceWriter.GetTraceMessages方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Wrapped
public void Wrapped()
{
MockMessageBroker broker = new MockMessageBroker();
MockExecutionTimer timer = new MockExecutionTimer();
MemoryTraceWriter innerWriter = new MemoryTraceWriter();
GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer, innerWriter);
writer.Trace(TraceLevel.Verbose, "Random text", null);
writer.Trace(TraceLevel.Error, "More random text", null);
Assert.AreEqual(2, writer.TraceMessages.Count);
Assert.AreEqual(2, innerWriter.GetTraceMessages().Count());
Assert.AreEqual("Verbose Random text", innerWriter.GetTraceMessages().ElementAt(0).Substring(24));
Assert.AreEqual("Error More random text", innerWriter.GetTraceMessages().ElementAt(1).Substring(24));
innerWriter.LevelFilter = TraceLevel.Warning;
writer.Trace(TraceLevel.Verbose, "Random text", null);
writer.Trace(TraceLevel.Warning, "More random text", null);
writer.Trace(TraceLevel.Error, "More random text", null);
Assert.AreEqual(4, innerWriter.GetTraceMessages().Count());
Assert.AreEqual(TraceLevel.Verbose, writer.LevelFilter);
}
示例2: Example
public void Example()
{
#region Usage
string json = @"{
'FullName': 'Dan Deleted',
'Deleted': true,
'DeletedDate': '2013-01-20T00:00:00'
}";
MemoryTraceWriter traceWriter = new MemoryTraceWriter();
Account account = JsonConvert.DeserializeObject<Account>(json, new JsonSerializerSettings
{
TraceWriter = traceWriter
});
Console.WriteLine(traceWriter.ToString());
// 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
// 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
// 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
// 2013-01-21T01:36:24.450 Verbose Deserialized JSON:
// {
// "FullName": "Dan Deleted",
// "Deleted": true,
// "DeletedDate": "2013-01-20T00:00:00"
// }
#endregion
Assert.AreEqual(4, traceWriter.GetTraceMessages().Count());
}
示例3: MemoryTraceWriterLimitTest
public void MemoryTraceWriterLimitTest()
{
MemoryTraceWriter traceWriter = new MemoryTraceWriter();
for (int i = 0; i < 1005; i++)
{
traceWriter.Trace(TraceLevel.Verbose, (i + 1).ToString(CultureInfo.InvariantCulture), null);
}
IList<string> traceMessages = traceWriter.GetTraceMessages().ToList();
Assert.AreEqual(1000, traceMessages.Count);
Assert.IsTrue(traceMessages.First().EndsWith(" 6"));
Assert.IsTrue(traceMessages.Last().EndsWith(" 1005"));
}
示例4: ShouldDeserialize_False
public void ShouldDeserialize_False()
{
string json = @"{'HasName':false,'Name':'Name!'}";
MemoryTraceWriter traceWriter = new MemoryTraceWriter();
ShouldDeserializeTestClass c = JsonConvert.DeserializeObject<ShouldDeserializeTestClass>(json, new JsonSerializerSettings
{
ContractResolver = ShouldDeserializeContractResolver.Instance,
TraceWriter = traceWriter
});
Assert.AreEqual(1, c.ExtensionData.Count);
Assert.AreEqual("Name!", (string)c.ExtensionData["Name"]);
Assert.AreEqual(false, c.HasName);
Assert.AreEqual(null, c.Name);
Assert.IsTrue(traceWriter.GetTraceMessages().Any(m => m.EndsWith("Verbose ShouldDeserialize result for property 'Name' on Newtonsoft.Json.Tests.Serialization.ShouldDeserializeTestClass: False. Path 'Name'.")));
}
示例5: ParseEntry
private JobLogEntry ParseEntry(string line)
{
var writer = new MemoryTraceWriter();
var old = _serializerSettings.TraceWriter;
_serializerSettings.TraceWriter = writer;
var result = JsonConvert.DeserializeObject<JobLogEntry>(line.Trim(), _serializerSettings);
_serializerSettings.TraceWriter = old;
foreach (var message in writer.GetTraceMessages())
{
Console.WriteLine(message);
}
return result;
}