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])); }
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); } }
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); }
private static List<LogEvent> ExtractLogEvents(NLogEvents events, Batch batch) { var logEventInfoList = events.ToEventInfo().ToList(); var timberMillEvents = logEventInfoList.ConvertAll(ei => TimberMillEventFactory(batch, ei)); return timberMillEvents; }