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


C# LogReceiverService.NLogEvents类代码示例

本文整理汇总了C#中NLog.LogReceiverService.NLogEvents的典型用法代码示例。如果您正苦于以下问题:C# NLogEvents类的具体用法?C# NLogEvents怎么用?C# NLogEvents使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NLogEvents类属于NLog.LogReceiverService命名空间,在下文中一共展示了NLogEvents类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessLogMessages

        /// <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);
        }
开发者ID:semirs,项目名称:CellAO,代码行数:32,代码来源:LogReceiverForwardingService.cs

示例2: 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

示例3: 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

示例4: CompareSerializationFormats

        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);
        }
开发者ID:ExM,项目名称:NLog,代码行数:52,代码来源:LogReceiverServiceTests.cs

示例5: LogEvents

        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);
        }
开发者ID:neutmute,项目名称:TimberMill,代码行数:17,代码来源:LogService.cs

示例6: ProcessLogMessages

        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);
            }
        }
开发者ID:CharlieBP,项目名称:NLog,代码行数:22,代码来源:NLogReceiver.svc.cs

示例7: 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

示例8: Send

        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
        }
开发者ID:304NotModified,项目名称:NLog-1,代码行数:93,代码来源:LogReceiverWebServiceTarget.cs

示例9: BeginProcessLogMessages

 /// <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);
 }
开发者ID:shadowca,项目名称:NLog,代码行数:13,代码来源:SoapLogReceiverClient.cs

示例10: ProcessLogMessagesAsync

 /// <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);
     }
 }
开发者ID:xiaopohou,项目名称:NLog,代码行数:15,代码来源:WcfLogReceiverClientFacade.cs

示例11: TranslateEvent

        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;
        }
开发者ID:bhaeussermann,项目名称:NLog,代码行数:44,代码来源:LogReceiverWebServiceTarget.cs

示例12: TranslateLogEvents

        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;
        }
开发者ID:bhaeussermann,项目名称:NLog,代码行数:58,代码来源:LogReceiverWebServiceTarget.cs

示例13: OnSend

 /// <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;
 }
开发者ID:bhaeussermann,项目名称:NLog,代码行数:10,代码来源:LogReceiverWebServiceTarget.cs

示例14: 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

示例15: TranslateLogEvents

        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;
        }
开发者ID:ExM,项目名称:NLog,代码行数:50,代码来源:LogReceiverWebServiceTarget.cs


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