當前位置: 首頁>>代碼示例>>C#>>正文


C# NLogEvents.ToEventInfo方法代碼示例

本文整理匯總了C#中NLog.LogReceiverService.NLogEvents.ToEventInfo方法的典型用法代碼示例。如果您正苦於以下問題:C# NLogEvents.ToEventInfo方法的具體用法?C# NLogEvents.ToEventInfo怎麽用?C# NLogEvents.ToEventInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NLog.LogReceiverService.NLogEvents的用法示例。


在下文中一共展示了NLogEvents.ToEventInfo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToLogEventInfoTest

        public void ToLogEventInfoTest()
        {
            var events = new NLogEvents
            {
                BaseTimeUtc = new DateTime(2010, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks,
                ClientName = "foo",
                LayoutNames = new StringCollection { "foo", "bar", "baz" },
                Strings = new StringCollection { "logger1", "logger2", "logger3", "zzz", "message1" },
                Events =
                    new[]
                    {
                        new NLogEvent
                        {
                            Id = 1,
                            LevelOrdinal = 2,
                            LoggerOrdinal = 0,
                            TimeDelta = 30000000,
                            MessageOrdinal = 4,
                            Values = "0|1|2"
                        },
                        new NLogEvent
                        {
                            Id = 2,
                            LevelOrdinal = 3,
                            LoggerOrdinal = 2,
                            MessageOrdinal = 4,
                            TimeDelta = 30050000,
                            Values = "0|1|3",
                        }
                    }
            };

            var converted = events.ToEventInfo();

            Assert.Equal(2, converted.Count);
            Assert.Equal("message1", converted[0].FormattedMessage);
            Assert.Equal("message1", converted[1].FormattedMessage);

            Assert.Equal(new DateTime(2010, 1, 1, 0, 0, 3, 0, DateTimeKind.Utc), converted[0].TimeStamp.ToUniversalTime());
            Assert.Equal(new DateTime(2010, 1, 1, 0, 0, 3, 5, DateTimeKind.Utc), converted[1].TimeStamp.ToUniversalTime());

            Assert.Equal("logger1", converted[0].LoggerName);
            Assert.Equal("logger3", converted[1].LoggerName);

            Assert.Equal(LogLevel.Info, converted[0].Level);
            Assert.Equal(LogLevel.Warn, converted[1].Level);

            Layout fooLayout = "${event-context:foo}";
            Layout barLayout = "${event-context:bar}";
            Layout bazLayout = "${event-context:baz}";

            Assert.Equal("logger1", fooLayout.Render(converted[0]));
            Assert.Equal("logger1", fooLayout.Render(converted[1]));

            Assert.Equal("logger2", barLayout.Render(converted[0]));
            Assert.Equal("logger2", barLayout.Render(converted[1]));

            Assert.Equal("logger3", bazLayout.Render(converted[0]));
            Assert.Equal("zzz", bazLayout.Render(converted[1]));
        }
開發者ID:Enzyoh,項目名稱:NLog,代碼行數:60,代碼來源:LogReceiverServiceTests.cs

示例2: ProcessLogMessages

        public void ProcessLogMessages(NLogEvents nevents)
        {
            var events = nevents.ToEventInfo("Client.");
            Console.WriteLine("in: {0} {1}", nevents.Events.Length, events.Count);

            foreach (var ev in events)
            {
                var logger = LogManager.GetLogger(ev.LoggerName);
                logger.Log(ev);
            }
        }
開發者ID:rameshr,項目名稱:NLog,代碼行數:11,代碼來源:LogReceiverServer.cs

示例3: NoLayoutsTest

        public void NoLayoutsTest()
        {
            var events = new NLogEvents
            {
                BaseTimeUtc = new DateTime(2010, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks,
                ClientName = "foo",
                LayoutNames = new StringCollection(),
                Strings = new StringCollection { "logger1", "logger2", "logger3", "zzz", "message1" },
                Events =
                    new[]
                    {
                        new NLogEvent
                        {
                            Id = 1,
                            LevelOrdinal = 2,
                            LoggerOrdinal = 0,
                            TimeDelta = 30000000,
                            MessageOrdinal = 4,
                            Values = null,
                        },
                        new NLogEvent
                        {
                            Id = 2,
                            LevelOrdinal = 3,
                            LoggerOrdinal = 2,
                            MessageOrdinal = 4,
                            TimeDelta = 30050000,
                            Values = null,
                        }
                    }
            };

            var converted = events.ToEventInfo();

            Assert.Equal(2, converted.Count);
            Assert.Equal("message1", converted[0].FormattedMessage);
            Assert.Equal("message1", converted[1].FormattedMessage);

            Assert.Equal(new DateTime(2010, 1, 1, 0, 0, 3, 0, DateTimeKind.Utc), converted[0].TimeStamp.ToUniversalTime());
            Assert.Equal(new DateTime(2010, 1, 1, 0, 0, 3, 5, DateTimeKind.Utc), converted[1].TimeStamp.ToUniversalTime());

            Assert.Equal("logger1", converted[0].LoggerName);
            Assert.Equal("logger3", converted[1].LoggerName);

            Assert.Equal(LogLevel.Info, converted[0].Level);
            Assert.Equal(LogLevel.Warn, converted[1].Level);
        }
開發者ID:senj,項目名稱:NLog,代碼行數:47,代碼來源:LogReceiverServiceTests.cs

示例4: ExtractLogEvents

 private static List<LogEvent> ExtractLogEvents(NLogEvents events, Batch batch)
 {
     var logEventInfoList = events.ToEventInfo().ToList();
     var timberMillEvents = logEventInfoList.ConvertAll(ei => TimberMillEventFactory(batch, ei));
     return timberMillEvents;
 }
開發者ID:neutmute,項目名稱:TimberMill,代碼行數:6,代碼來源:LogService.cs


注:本文中的NLog.LogReceiverService.NLogEvents.ToEventInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。