예제 #1
0
        private IDictionary<string, object> GetLogEventProperties(LogEventBase logEvent)
        {
            Dictionary<string, object> propValues = new Dictionary<string, object>();

            PropertyInfo[] props;
            Type type = logEvent.GetType();

            if (!logEventPropertyCache.TryGetValue(type, out props))
            {
                props = type.GetProperties();
                logEventPropertyCache.TryAdd(type, props);
            }

            foreach (var prop in props)
            {
                object value = prop.GetValue(logEvent);
                propValues.Add(prop.Name, value);
            }

            return propValues;
        }
예제 #2
0
        public void Info(LogEventBase logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }

            if (log4netLogEventLog.IsInfoEnabled)
            {
                logEvent.Logged = DateTime.UtcNow;

                IDictionary<string, object> properties = GetLogEventProperties(logEvent);                

                LoggingEventData loggingEventData = new LoggingEventData();
                loggingEventData.Level = Level.Info;
                loggingEventData.LoggerName = log4netLogEventLog.Logger.Name;
                loggingEventData.TimeStamp = logEvent.Logged;

                LoggingEvent loggingEvent = new LoggingEvent(loggingEventData);

                foreach (var kvp in properties)
                {
                    loggingEvent.Properties[kvp.Key] = kvp.Value;
                }

                log4netLogEventLog.Logger.Log(loggingEvent);
            }
        }