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


C# MemoryTraceWriter.GetTraceMessages方法代码示例

本文整理汇总了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);
    }
开发者ID:modulexcite,项目名称:Newtonsoft.Json.Glimpse,代码行数:25,代码来源:GlimpseTraceWriterTests.cs

示例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());
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:30,代码来源:TraceWriter.cs

示例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"));
        }
开发者ID:SeanmanX,项目名称:opandroid,代码行数:16,代码来源:TraceWriterTests.cs

示例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'.")));
        }
开发者ID:veblush,项目名称:Newtonsoft.Json,代码行数:18,代码来源:ShouldSerializeTests.cs

示例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;
 }
开发者ID:JetBrains,项目名称:NuGetOperations,代码行数:13,代码来源:JobLog.cs


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