/// <summary> /// Processes the log messages. /// </summary> /// <param name="events">The events to process.</param> public void ProcessLogMessages(NLogEvents events) { var baseTimeUtc = new DateTime(events.BaseTimeUtc, DateTimeKind.Utc); var logEvents = new LogEventInfo[events.Events.Length]; // convert transport representation of log events into workable LogEventInfo[] for (int j = 0; j < events.Events.Length; ++j) { var ev = events.Events[j]; LogLevel level = LogLevel.FromOrdinal(ev.LevelOrdinal); string loggerName = events.Strings[ev.LoggerOrdinal]; var logEventInfo = new LogEventInfo(); logEventInfo.Level = level; logEventInfo.LoggerName = loggerName; logEventInfo.TimeStamp = baseTimeUtc.AddTicks(ev.TimeDelta); logEventInfo.Message = events.Strings[ev.MessageOrdinal]; logEventInfo.Properties.Add("ClientName", events.ClientName); for (int i = 0; i < events.LayoutNames.Count; ++i) { logEventInfo.Properties.Add(events.LayoutNames[i], events.Strings[ev.ValueIndexes[i]]); } logEvents[j] = logEventInfo; } this.ProcessLogMessages(logEvents); }
/// <summary> /// Processes the log messages. /// </summary> /// <param name="events">The events to process.</param> public void ProcessLogMessages(NLogEvents events) { var baseTimeUtc = new DateTime(events.BaseTimeUtc, DateTimeKind.Utc); var logEvents = new LogEventInfo[events.Events.Length]; // convert transport representation of log events into workable LogEventInfo[] for (int j = 0; j < events.Events.Length; ++j) { var ev = events.Events[j]; LogLevel level = LogLevel.FromOrdinal(ev.LevelOrdinal); string loggerName = events.Strings[ev.LoggerOrdinal]; var logEventInfo = new LogEventInfo(); logEventInfo.Level = level; logEventInfo.LoggerName = loggerName; logEventInfo.TimeStamp = baseTimeUtc.AddTicks(ev.TimeDelta); logEventInfo.Message = events.Strings[ev.MessageOrdinal]; logEventInfo.Properties.Add("ClientName", events.ClientName); for (int i = 0; i < events.LayoutNames.Count; ++i) { logEventInfo.Properties.Add(events.LayoutNames[i], ev.Values[i]); } logEvents[j] = logEventInfo; } this.ProcessLogMessages(logEvents); }
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 IAsyncResult BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState) { return(this.BeginInvoke( "ProcessLogMessages", new object[] { events }, callback, asyncState)); }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> /// <param name="userState">User-specific state.</param> public void ProcessLogMessagesAsync(NLogEvents events, object userState) { this.InvokeAsync( this.OnBeginProcessLogMessages, new object[] { events }, this.OnEndProcessLogMessages, this.OnProcessLogMessagesCompleted, userState); }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> public void ProcessLogMessagesAsync(NLogEvents events) { if (m_useOneWay) { m_oneWayClient.ProcessLogMessagesAsync(events); } else { m_twoWayClient.ProcessLogMessagesAsync(events); } }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> /// <param name="userState">User-specific state.</param> public void ProcessLogMessagesAsync(NLogEvents events, object userState) { if (m_useOneWay) { m_oneWayClient.ProcessLogMessagesAsync(events, userState); } else { m_twoWayClient.ProcessLogMessagesAsync(events, userState); } }
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 CompareSerializationFormats() { var events = new NLogEvents { BaseTimeUtc = DateTime.UtcNow.Ticks, ClientName = "foo", LayoutNames = new StringCollection { "foo", "bar", "baz" }, Strings = new StringCollection { "logger1", "logger2", "logger3" }, Events = new[] { new NLogEvent { Id = 1, LevelOrdinal = 2, LoggerOrdinal = 0, TimeDelta = 34, Values = "1|2|3" }, new NLogEvent { Id = 2, LevelOrdinal = 3, LoggerOrdinal = 2, TimeDelta = 345, Values = "1|2|3", } } }; var serializer1 = new XmlSerializer(typeof(NLogEvents)); var sw1 = new StringWriter(); using (var writer1 = XmlWriter.Create(sw1, new XmlWriterSettings { Indent = true })) { var namespaces = new XmlSerializerNamespaces(); namespaces.Add("i", "http://www.w3.org/2001/XMLSchema-instance"); serializer1.Serialize(writer1, events, namespaces); } var serializer2 = new DataContractSerializer(typeof(NLogEvents)); var sw2 = new StringWriter(); using (var writer2 = XmlWriter.Create(sw2, new XmlWriterSettings { Indent = true })) { serializer2.WriteObject(writer2, events); } var xml1 = sw1.ToString(); var xml2 = sw2.ToString(); Assert.AreEqual(xml1, xml2); }
/// <summary> /// Converts the <see cref="NLogEvent"/> to <see cref="LogEventInfo"/>. /// </summary> /// <param name="context">The <see cref="NLogEvent"/> object this <see cref="NLogEvent" /> is part of..</param> /// <param name="loggerNamePrefix">The logger name prefix to prepend in front of the logger name.</param> /// <returns>Converted <see cref="LogEventInfo"/>.</returns> internal LogEventInfo ToEventInfo(NLogEvents context, string loggerNamePrefix) { var result = new LogEventInfo(LogLevel.FromOrdinal(this.LevelOrdinal), loggerNamePrefix + context.Strings[this.LoggerOrdinal], context.Strings[this.MessageOrdinal]); result.TimeStamp = new DateTime(context.BaseTimeUtc + this.TimeDelta, DateTimeKind.Utc).ToLocalTime(); for (int i = 0; i < context.LayoutNames.Count; ++i) { string layoutName = context.LayoutNames[i]; string layoutValue = context.Strings[this.ValueIndexes[i]]; result.Properties[layoutName] = layoutValue; } return(result); }
public void LogEvents(NLogEvents events) { Source source = ParseAndCreateSource(events.ClientName); if (source == null) { Log.Error("Ignoring received events"); return; } var batch = _batchRepository.Create(source); var timberMillEvents = ExtractLogEvents(events, batch); timberMillEvents.ForEach(_eventRepository.Save); Log.Info("Received {0} events from {1}", timberMillEvents.Count, source); }
public void ProcessLogMessages(NLogEvents events) { DateTime baseTimeUtc = new DateTime(events.BaseTimeUtc, DateTimeKind.Utc); foreach (var ev in events.Events) { LogLevel level = LogLevel.FromOrdinal(ev.LevelOrdinal); string loggerName = events.LoggerNames[ev.LoggerOrdinal]; Logger logger = LogManager.GetLogger(loggerName); var logEventInfo = new LogEventInfo(); logEventInfo.Level = level; logEventInfo.LoggerName = loggerName; logEventInfo.TimeStamp = baseTimeUtc.AddTicks(ev.TimeDelta); logEventInfo.Properties.Add("ClientName", events.ClientName); for (int i = 0; i < events.LayoutNames.Count; ++i) { logEventInfo.Properties.Add(events.LayoutNames[i], ev.Values[i]); } logger.Log(logEventInfo); } }
private NLogEvents TranslateLogEvents(AsyncLogEventInfo[] logEvents) { if (logEvents.Length == 0 && !LogManager.ThrowExceptions) { InternalLogger.Error("LogEvents array is empty, sending empty event..."); return new NLogEvents(); } string clientID = string.Empty; if (this.ClientId != null) { clientID = this.ClientId.Render(logEvents[0].LogEvent); } var networkLogEvents = new NLogEvents { ClientName = clientID, LayoutNames = new StringCollection(), Strings = new StringCollection(), BaseTimeUtc = logEvents[0].LogEvent.TimeStamp.ToUniversalTime().Ticks }; var stringTable = new Dictionary<string, int>(); for (int i = 0; i < this.Parameters.Count; ++i) { networkLogEvents.LayoutNames.Add(this.Parameters[i].Name); } if (this.IncludeEventProperties) { for (int i = 0; i < logEvents.Length; ++i) { var ev = logEvents[i].LogEvent; // add all event-level property names in 'LayoutNames' collection. foreach (var prop in ev.Properties) { string propName = prop.Key as string; if (propName != null) { if (!networkLogEvents.LayoutNames.Contains(propName)) { networkLogEvents.LayoutNames.Add(propName); } } } } } networkLogEvents.Events = new NLogEvent[logEvents.Length]; for (int i = 0; i < logEvents.Length; ++i) { networkLogEvents.Events[i] = this.TranslateEvent(logEvents[i].LogEvent, networkLogEvents, stringTable); } return networkLogEvents; }
/// <summary> /// Called when log events are being sent (test hook). /// </summary> /// <param name="events">The events.</param> /// <param name="asyncContinuations">The async continuations.</param> /// <returns>True if events should be sent, false to stop processing them.</returns> protected internal virtual bool OnSend(NLogEvents events, IEnumerable<AsyncLogEventInfo> asyncContinuations) { return true; }
/// <summary> /// Begins processing of log messages. /// </summary> /// <param name="events">The events to send.</param> /// <param name="callback">The callback.</param> /// <param name="asyncState">Asynchronous state.</param> /// <returns> /// IAsyncResult value which can be passed to <see cref="ILogReceiverOneWayClient.EndProcessLogMessages"/>. /// </returns> IAsyncResult ILogReceiverOneWayClient.BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState) { return(this.Channel.BeginProcessLogMessages(events, callback, asyncState)); }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> public void ProcessLogMessagesAsync(NLogEvents events) { this.ProcessLogMessagesAsync(events, null); }
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); }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> /// <param name="userState">User-specific state.</param> public void ProcessLogMessagesAsync(NLogEvents events, object userState) { ProxiedClient.ProcessLogMessagesAsync(events, userState); }
/// <summary> /// Begins processing of log messages. /// </summary> /// <param name="events">The events to send.</param> /// <param name="callback">The callback.</param> /// <param name="asyncState">Asynchronous state.</param> /// <returns> /// IAsyncResult value which can be passed to <see cref="ILogReceiverOneWayClient.EndProcessLogMessages"/>. /// </returns> public IAsyncResult BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState) { return(ProxiedClient.BeginProcessLogMessages(events, callback, asyncState)); }
public void ProcessLogMessages(NLogEvents events) { this.Invoke("ProcessLogMessages", new object[] { events }); }
private NLogEvents TranslateLogEvents(AsyncLogEventInfo[] logEvents) { string clientID = string.Empty; if (ClientId != null) clientID = ClientId.Render(logEvents[0].LogEvent); var networkLogEvents = new NLogEvents { ClientName = clientID, LayoutNames = new StringCollection(), Strings = new StringCollection(), BaseTimeUtc = logEvents[0].LogEvent.TimeStamp.ToUniversalTime().Ticks }; var stringTable = new Dictionary<string, int>(); for (int i = 0; i < Parameters.Count; ++i) { networkLogEvents.LayoutNames.Add(Parameters[i].Name); } if (IncludeEventProperties) { for (int i = 0; i < logEvents.Length; ++i) { var ev = logEvents[i].LogEvent; // add all event-level property names in 'LayoutNames' collection. foreach (var prop in ev.Properties) { string propName = prop.Key as string; if (propName != null) { if (!networkLogEvents.LayoutNames.Contains(propName)) { networkLogEvents.LayoutNames.Add(propName); } } } } } networkLogEvents.Events = new NLogEvent[logEvents.Length]; for (int i = 0; i < logEvents.Length; ++i) { networkLogEvents.Events[i] = TranslateEvent(logEvents[i].LogEvent, networkLogEvents, stringTable); } return networkLogEvents; }
public void ToLogEventInfoTest() { LogManager.Configuration = CreateConfigurationFromString(@" <nlog> <targets> <target name='debug1' type='Debug' layout='${message} ${event-context:foo} ${event-context:bar} ${event-context:baz}' /> <target name='debug2' type='Debug' layout='${message} ${event-context:foo} ${event-context:bar} ${event-context:baz}' /> <target name='debug3' type='Debug' layout='${message} ${event-context:foo} ${event-context:bar} ${event-context:baz}' /> </targets> <rules> <logger name='logger1' minlevel='Trace' writeTo='debug1' /> <logger name='logger2' minlevel='Trace' writeTo='debug2' /> <logger name='logger3' minlevel='Trace' writeTo='debug3' /> </rules> </nlog>"); var service = new LogReceiverForwardingService(); 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", } } }; service.ProcessLogMessages(events); this.AssertDebugCounter("debug1", 1); this.AssertDebugCounter("debug2", 0); this.AssertDebugCounter("debug3", 1); this.AssertDebugLastMessage("debug1", "message1 logger1 logger2 logger3"); this.AssertDebugLastMessage("debug3", "message1 logger1 logger2 zzz"); }
public void ProcessLogMessages(NLogEvents events) { this.Invoke("ProcessLogMessages", new object[] { events }); }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> /// <param name="userState">User-specific state.</param> public void ProcessLogMessagesAsync(NLogEvents events, object userState) { ProxiedClient.ProcessLogMessagesAsync(events, userState); }
private NLogEvent TranslateEvent(LogEventInfo eventInfo, NLogEvents context, Dictionary<string, int> stringTable) { var nlogEvent = new NLogEvent(); nlogEvent.Id = eventInfo.SequenceID; nlogEvent.MessageOrdinal = AddValueAndGetStringOrdinal(context, stringTable, eventInfo.FormattedMessage); nlogEvent.LevelOrdinal = eventInfo.Level.Ordinal; nlogEvent.LoggerOrdinal = AddValueAndGetStringOrdinal(context, stringTable, eventInfo.LoggerName); nlogEvent.TimeDelta = eventInfo.TimeStamp.ToUniversalTime().Ticks - context.BaseTimeUtc; for (int i = 0; i < this.Parameters.Count; ++i) { var param = this.Parameters[i]; var value = param.Layout.Render(eventInfo); int stringIndex = AddValueAndGetStringOrdinal(context, stringTable, value); nlogEvent.ValueIndexes.Add(stringIndex); } // layout names beyond Parameters.Count are per-event property names. for (int i = this.Parameters.Count; i < context.LayoutNames.Count; ++i) { string value; object propertyValue; if (eventInfo.Properties.TryGetValue(context.LayoutNames[i], out propertyValue)) { value = Convert.ToString(propertyValue, CultureInfo.InvariantCulture); } else { value = string.Empty; } int stringIndex = AddValueAndGetStringOrdinal(context, stringTable, value); nlogEvent.ValueIndexes.Add(stringIndex); } if (eventInfo.Exception != null) { nlogEvent.ValueIndexes.Add(AddValueAndGetStringOrdinal(context, stringTable, eventInfo.Exception.ToString())); } return nlogEvent; }
/// <summary> /// Begins processing of log messages. /// </summary> /// <param name="events">The events.</param> /// <param name="callback">The callback.</param> /// <param name="asyncState">Asynchronous state.</param> /// <returns> /// IAsyncResult value which can be passed to <see cref="ILogReceiverClient.EndProcessLogMessages"/>. /// </returns> public IAsyncResult BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState) { return this.BeginInvoke("ProcessLogMessages", new object[] { events }, callback, asyncState); }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> public void ProcessLogMessagesAsync(NLogEvents events) { ProxiedClient.ProcessLogMessagesAsync(events); }
private void Send(NLogEvents events, IEnumerable<AsyncLogEventInfo> asyncContinuations) { if (!this.OnSend(events, asyncContinuations)) { return; } #if WCF_SUPPORTED WcfLogReceiverClient client; if (string.IsNullOrEmpty(this.EndpointConfigurationName)) { // endpoint not specified - use BasicHttpBinding Binding binding; #if !SILVERLIGHT2 if (this.UseBinaryEncoding) { binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()); } else #endif { binding = new BasicHttpBinding(); } client = new WcfLogReceiverClient(binding, new EndpointAddress(this.EndpointAddress)); } else { client = new WcfLogReceiverClient(this.EndpointConfigurationName, new EndpointAddress(this.EndpointAddress)); } client.ProcessLogMessagesCompleted += (sender, e) => { // report error to the callers foreach (var ev in asyncContinuations) { ev.Continuation(e.Error); } // send any buffered events this.SendBufferedEvents(); }; this.inCall = true; #if SILVERLIGHT if (!Deployment.Current.Dispatcher.CheckAccess()) { Deployment.Current.Dispatcher.BeginInvoke(() => client.ProcessLogMessagesAsync(events)); } else { client.ProcessLogMessagesAsync(events); } #else client.ProcessLogMessagesAsync(events); #endif #else var client = new SoapLogReceiverClient(this.EndpointAddress); this.inCall = true; client.BeginProcessLogMessages( events, result => { Exception exception = null; try { client.EndProcessLogMessages(result); } catch (Exception ex) { if (ex.MustBeRethrown()) { throw; } exception = ex; } // report error to the callers foreach (var ev in asyncContinuations) { ev.Continuation(exception); } // send any buffered events this.SendBufferedEvents(); }, null); #endif }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> public void ProcessLogMessagesAsync(NLogEvents events) { ProxiedClient.ProcessLogMessagesAsync(events); }
private void Send(NLogEvents events, IEnumerable<AsyncLogEventInfo> asyncContinuations) { if (!OnSend(events, asyncContinuations)) { return; } WcfLogReceiverClient client; if (string.IsNullOrEmpty(EndpointConfigurationName)) { // endpoint not specified - use BasicHttpBinding Binding binding; if (UseBinaryEncoding) { binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()); } else { binding = new BasicHttpBinding(); } client = new WcfLogReceiverClient(binding, new EndpointAddress(EndpointAddress)); } else { client = new WcfLogReceiverClient(EndpointConfigurationName, new EndpointAddress(EndpointAddress)); } client.ProcessLogMessagesCompleted += (sender, e) => { // report error to the callers foreach (var ev in asyncContinuations) { ev.Continuation(e.Error); } // send any buffered events SendBufferedEvents(); }; inCall = true; client.ProcessLogMessagesAsync(events); }
/// <summary> /// Begins processing of log messages. /// </summary> /// <param name="events">The events to send.</param> /// <param name="callback">The callback.</param> /// <param name="asyncState">Asynchronous state.</param> /// <returns> /// IAsyncResult value which can be passed to <see cref="ILogReceiverOneWayClient.EndProcessLogMessages"/>. /// </returns> public abstract IAsyncResult BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState);
private NLogEvents TranslateLogEvents(LogEventInfo[] logEvents) { var networkLogEvents = new NLogEvents { ClientName = this.ClientID, LayoutNames = new ListOfStrings(), LoggerNames = new ListOfStrings(), BaseTimeUtc = logEvents[0].TimeStamp.ToUniversalTime().Ticks }; for (int i = 0; i < this.Parameters.Count; ++i) { networkLogEvents.LayoutNames.Add(this.Parameters[i].Name); } networkLogEvents.Events = new NLogEvent[logEvents.Length]; for (int i = 0; i < logEvents.Length; ++i) { networkLogEvents.Events[i] = this.TranslateEvent(logEvents[i], networkLogEvents); } return networkLogEvents; }
/// <summary> /// Processes the log messages. /// </summary> /// <param name="events">The events.</param> public void ProcessLogMessages(NLogEvents events) { if (CountdownEvent == null) { throw new Exception("test not prepared well"); } recievedEvents.Add(events); CountdownEvent.Signal(); }
private static List<LogEvent> ExtractLogEvents(NLogEvents events, Batch batch) { var logEventInfoList = events.ToEventInfo().ToList(); var timberMillEvents = logEventInfoList.ConvertAll(ei => TimberMillEventFactory(batch, ei)); return timberMillEvents; }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> /// <param name="userState">User-specific state.</param> public void ProcessLogMessagesAsync(NLogEvents events, object userState) { if (m_useOneWay) { m_oneWayClient.ProcessLogMessagesAsync(events, userState); } else { m_twoWayClient.ProcessLogMessagesAsync(events, userState); } }
private NLogEvent TranslateEvent(LogEventInfo eventInfo, NLogEvents context) { var nlogEvent = new NLogEvent(); nlogEvent.Id = eventInfo.SequenceID; nlogEvent.Values = new ListOfStrings(); nlogEvent.LevelOrdinal = eventInfo.Level.Ordinal; int loggerOrdinal = context.LoggerNames.IndexOf(eventInfo.LoggerName); if (loggerOrdinal < 0) { loggerOrdinal = context.LoggerNames.Count; context.LoggerNames.Add(eventInfo.LoggerName); } nlogEvent.LoggerOrdinal = loggerOrdinal; nlogEvent.TimeDelta = eventInfo.TimeStamp.ToUniversalTime().Ticks - context.BaseTimeUtc; for (int i = 0; i < this.Parameters.Count; ++i) { var param = this.Parameters[i]; nlogEvent.Values.Add(param.Layout.Render(eventInfo)); } return nlogEvent; }
/// <summary> /// Processes the log messages asynchronously. /// </summary> /// <param name="events">The events to send.</param> public void ProcessLogMessagesAsync(NLogEvents events) { if (m_useOneWay) { m_oneWayClient.ProcessLogMessagesAsync(events); } else { m_twoWayClient.ProcessLogMessagesAsync(events); } }
private void Send(NLogEvents events, AsyncContinuation[] asyncContinuations) { #if WCF_SUPPORTED WcfLogReceiverClient client; if (string.IsNullOrEmpty(this.EndpointConfigurationName)) { // endpoint not specified - use BasicHttpBinding var binding = new BasicHttpBinding(); client = new WcfLogReceiverClient(binding, new EndpointAddress(this.EndpointAddress)); } else { client = new WcfLogReceiverClient(this.EndpointConfigurationName, new EndpointAddress(this.EndpointAddress)); } client.ProcessLogMessagesCompleted += (sender, e) => { // report error to the callers foreach (var cont in asyncContinuations) { cont(e.Error); } }; client.ProcessLogMessagesAsync(events); #endif }
private static int AddValueAndGetStringOrdinal(NLogEvents context, Dictionary<string, int> stringTable, string value) { int stringIndex; if (!stringTable.TryGetValue(value, out stringIndex)) { stringIndex = context.Strings.Count; stringTable.Add(value, stringIndex); context.Strings.Add(value); } return stringIndex; }
protected internal override bool OnSend(NLogEvents events, IEnumerable<AsyncLogEventInfo> asyncContinuations) { this.LastPayload = events; ++this.SendCount; foreach (var ac in asyncContinuations) { ac.Continuation(null); } return false; }
private void Send(NLogEvents events, IEnumerable<AsyncLogEventInfo> asyncContinuations) { if (!this.OnSend(events, asyncContinuations)) { return; } #if WCF_SUPPORTED var client = CreateLogReceiver(); client.ProcessLogMessagesCompleted += (sender, e) => { // report error to the callers foreach (var ev in asyncContinuations) { ev.Continuation(e.Error); } // send any buffered events this.SendBufferedEvents(); }; this.inCall = true; #if SILVERLIGHT if (!Deployment.Current.Dispatcher.CheckAccess()) { Deployment.Current.Dispatcher.BeginInvoke(() => client.ProcessLogMessagesAsync(events)); } else { client.ProcessLogMessagesAsync(events); } #else client.ProcessLogMessagesAsync(events); #endif #else var client = new SoapLogReceiverClient(this.EndpointAddress); this.inCall = true; client.BeginProcessLogMessages( events, result => { Exception exception = null; try { client.EndProcessLogMessages(result); } catch (Exception ex) { if (ex.MustBeRethrown()) { throw; } exception = ex; } // report error to the callers foreach (var ev in asyncContinuations) { ev.Continuation(exception); } // send any buffered events this.SendBufferedEvents(); }, null); #endif }
/// <summary> /// Begins processing of log messages. /// </summary> /// <param name="events">The events to send.</param> /// <param name="callback">The callback.</param> /// <param name="asyncState">Asynchronous state.</param> /// <returns> /// IAsyncResult value which can be passed to <see cref="ILogReceiverOneWayClient.EndProcessLogMessages"/>. /// </returns> public override IAsyncResult BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState) { return(this.Channel.BeginProcessLogMessages(events, callback, asyncState)); }
/// <summary> /// Converts the <see cref="NLogEvent"/> to <see cref="LogEventInfo"/>. /// </summary> /// <param name="context">The <see cref="NLogEvent"/> object this <see cref="NLogEvent" /> is part of..</param> /// <param name="loggerNamePrefix">The logger name prefix to prepend in front of the logger name.</param> /// <returns>Converted <see cref="LogEventInfo"/>.</returns> internal LogEventInfo ToEventInfo(NLogEvents context, string loggerNamePrefix) { var result = new LogEventInfo(LogLevel.FromOrdinal(LevelOrdinal), loggerNamePrefix + context.Strings[LoggerOrdinal], context.Strings[MessageOrdinal]); result.TimeStamp = new DateTime(context.BaseTimeUtc + TimeDelta, DateTimeKind.Utc).ToLocalTime(); for (int i = 0; i < context.LayoutNames.Count; ++i) { string layoutName = context.LayoutNames[i]; string layoutValue = context.Strings[ValueIndexes[i]]; result.Properties[layoutName] = layoutValue; } return result; }
/// <summary> /// Begins processing of log messages. /// </summary> /// <param name="events">The events to send.</param> /// <param name="callback">The callback.</param> /// <param name="asyncState">Asynchronous state.</param> /// <returns> /// IAsyncResult value which can be passed to <see cref="ILogReceiverOneWayClient.EndProcessLogMessages"/>. /// </returns> public IAsyncResult BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, object asyncState) { return ProxiedClient.BeginProcessLogMessages(events, callback, asyncState); }