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


C# Log.All方法代码示例

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


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

示例1: TestProtoBufSerialization

        public async Task TestProtoBufSerialization()
        {
            Trace.WriteLine(RuntimeTypeModel.Default.GetSchema(typeof(Log)));
            const int testCount = 5;

            Log[] logs = new Log[testCount];
            for (int m = 0; m < testCount; m++)
                logs[m] = new Log(
                    new LogContext().Set("Test No", m),
                    new Exception("Exception", new Exception("Inner exception")),
                    LoggingLevel.Information,
                    () => Resources.TestString,
                    m,
                    Guid.NewGuid()).Add();

            await Log.Flush().ConfigureAwait(false);

            CollectionAssert.AllItemsAreNotNull(logs);
            Assert.IsTrue(logs.All(l => l.MessageFormat == Resources.TestString), "Logs contain incorrect message format.");

            List<Log> logs2 = new List<Log>();
            using (MemoryStream memoryStream = new MemoryStream())
            {
                foreach (Log log in logs)
                    Serializer.SerializeWithLengthPrefix(memoryStream, log, PrefixStyle.Base128);

                Trace.WriteLine(string.Format("Serialized logs took up {0} bytes.", memoryStream.Position));
                memoryStream.Seek(0, SeekOrigin.Begin);

                while (memoryStream.Position < memoryStream.Length)
                    logs2.Add(Serializer.DeserializeWithLengthPrefix<Log>(memoryStream, PrefixStyle.Base128));
            }
            Assert.IsNotNull(logs2);
            List<Log> result = logs2.ToList();
            Assert.AreEqual(logs.Length, result.Count);
            for (int i = 0; i < logs.Length; i++)
                Assert.AreEqual(logs[i].ToString(), result[i].ToString());
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:38,代码来源:LoggingTest.cs

示例2: TestProtoBufEnumerationSerialization

        public async Task TestProtoBufEnumerationSerialization()
        {
            Trace.WriteLine(RuntimeTypeModel.Default.GetSchema(typeof(IEnumerable<Log>)));
            const int testCount = 5;

            Log[] logs = new Log[testCount];
            for (int m = 0; m < testCount; m++)
                logs[m] = new Log(
                    new LogContext().Set("Test No", m),
                    new Exception("Exception", new Exception("Inner exception")),
                    LoggingLevel.Information,
                    () => Resources.TestString,
                    m,
                    Guid.NewGuid())
                    .Add();

            await Log.Flush().ConfigureAwait(false);

            CollectionAssert.AllItemsAreNotNull(logs);
            Assert.IsTrue(logs.All(l => l.MessageFormat == Resources.TestString), "Logs contain incorrect message format.");

            IEnumerable<Log> logs2;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                TestLogEnumeration test = new TestLogEnumeration(logs);
                Serializer.Serialize(memoryStream, test);

                Trace.WriteLine(string.Format("Serialized logs took up {0} bytes.", memoryStream.Position));
                memoryStream.Seek(0, SeekOrigin.Begin);

                //logs2 = Serializer.Deserialize<IEnumerable<Log>>(memoryStream); This doesnt work with the Trace.WriteLine at the top
                TestLogEnumeration test2 = Serializer.Deserialize<TestLogEnumeration>(memoryStream);
                logs2 = test2.Logs;
                Assert.AreEqual(memoryStream.Position, memoryStream.Length);
            }
            Assert.IsNotNull(logs2);
            List<Log> result = logs2.ToList();
            Assert.AreEqual(logs.Length, result.Count);
            for (int i = 0; i < logs.Length; i++)
                Assert.AreEqual(logs[i].ToString(), result[i].ToString());
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:41,代码来源:LoggingTest.cs

示例3: TestDataContractSerialization

        public async Task TestDataContractSerialization()
        {
            const int testCount = 5;

            Log[] logs = new Log[testCount];
            for (int m = 0; m < testCount; m++)
                logs[m] = new Log(
                    new LogContext().Set("Test No", m),
                    new Exception("Exception", new Exception("Inner exception")),
                    LoggingLevel.Information,
                    "Test Message {0} - {1}",
                    m,
                    Guid.NewGuid()).Add();

            await Log.Flush().ConfigureAwait(false);

            CollectionAssert.AllItemsAreNotNull(logs);
            Assert.IsTrue(logs.All(l => l.MessageFormat == "Test Message {0} - {1}"), "Logs contain incorrect message format.");

            DataContractSerializer serializer = new DataContractSerializer(typeof(IEnumerable<Log>));
            IEnumerable<Log> logs2;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                serializer.WriteObject(memoryStream, logs);

                memoryStream.Seek(0, SeekOrigin.Begin);

                logs2 = serializer.ReadObject(memoryStream) as IEnumerable<Log>;

                memoryStream.Seek(0, SeekOrigin.Begin);
                XDocument doc = XDocument.Load(memoryStream);
                Trace.WriteLine(doc.ToString());
            }
            Assert.IsNotNull(logs2);
            List<Log> result = logs2.ToList();
            Assert.AreEqual(logs.Length, result.Count);
            for (int i = 0; i < logs.Length; i++)
                Assert.AreEqual(logs[i].ToString(), result[i].ToString());
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:39,代码来源:LoggingTest.cs


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