Esempio n. 1
0
        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;
        }
        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;
        }
        private NLogEvent TranslateEvent(LogEventInfo eventInfo, NLogEvents context, Dictionary<string, int> stringTable)
        {
            var nlogEvent = new NLogEvent();
            nlogEvent.Id = eventInfo.SequenceID;
            nlogEvent.MessageOrdinal = GetStringOrdinal(context, stringTable, eventInfo.FormattedMessage);
            nlogEvent.LevelOrdinal = eventInfo.Level.Ordinal;
            nlogEvent.LoggerOrdinal = GetStringOrdinal(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 = GetStringOrdinal(context, stringTable, value);

                nlogEvent.ValueIndexes.Add(stringIndex);
            }

            return nlogEvent;
        }