예제 #1
0
        private NLogEvents TranslateLogEvents(IList <AsyncLogEventInfo> logEvents)
        {
            if (logEvents.Count == 0 && !LogManager.ThrowExceptions)
            {
                InternalLogger.Error("LogReceiverServiceTarget(Name={0}): LogEvents array is empty, sending empty event...", Name);
                return(new NLogEvents());
            }

            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)
            {
                AddEventProperties(logEvents, networkLogEvents);
            }

            networkLogEvents.Events = new NLogEvent[logEvents.Count];
            for (int i = 0; i < logEvents.Count; ++i)
            {
                AsyncLogEventInfo ev = logEvents[i];
                networkLogEvents.Events[i] = TranslateEvent(ev.LogEvent, networkLogEvents, stringTable);
            }

            return(networkLogEvents);
        }
예제 #2
0
        private NLogEvents TranslateLogEvents(IList <AsyncLogEventInfo> logEvents)
        {
            if (logEvents.Count == 0 && !LogManager.ThrowExceptions)
            {
                InternalLogger.Error("LogEvents array is empty, sending empty event...");
                return(new NLogEvents());
            }

            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.Count; ++i)
                {
                    var ev = logEvents[i].LogEvent;
                    MergeEventProperties(ev);

                    if (ev.HasProperties)
                    {
                        // 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.Count];
            for (int i = 0; i < logEvents.Count; ++i)
            {
                AsyncLogEventInfo ev = logEvents[i];
                networkLogEvents.Events[i] = TranslateEvent(ev.LogEvent, networkLogEvents, stringTable);
            }

            return(networkLogEvents);
        }