示例#1
0
        private void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localizable(false)] string message, object[] arguments, int? eventId)
        {
            var ev = new LogEventInfo();

            ev.LoggerName = (loggerName ?? Name) ?? string.Empty;

            #if !NET_CF
            if (AutoLoggerName)
            {
                var stack = new StackTrace();
                var userFrameIndex = -1;
                MethodBase userMethod = null;

                for (var i = 0; i < stack.FrameCount; ++i)
                {
                    var frame = stack.GetFrame(i);
                    var method = frame.GetMethod();

                    if (method.DeclaringType == GetType())
                    {
                        // skip all methods of this type
                        continue;
                    }

                    if (method.DeclaringType.Assembly == systemAssembly)
                    {
                        // skip all methods from System.dll
                        continue;
                    }

                    userFrameIndex = i;
                    userMethod = method;
                    break;
                }

                if (userFrameIndex >= 0)
                {
                    ev.SetStackTrace(stack, userFrameIndex);
                    if (userMethod.DeclaringType != null)
                    {
                        ev.LoggerName = userMethod.DeclaringType.FullName;
                    }
                }
            }
            #endif

            ev.TimeStamp = CurrentTimeGetter.Now;
            ev.Message = message;
            ev.Parameters = arguments;
            ev.Level = forceLogLevel ?? logLevel;

            if (eventId.HasValue)
            {
                ev.Properties.Add("EventID", eventId.Value);
            }

            var logger = LogManager.GetLogger(ev.LoggerName);
            logger.Log(ev);
        }
示例#2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="LogEventInfo" /> class.
        /// </summary>
        /// <param name="level">Log level.</param>
        /// <param name="loggerName">Logger name.</param>
        /// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
        /// <param name="message">Log message including parameter placeholders.</param>
        /// <param name="parameters">Parameter array.</param>
        /// <param name="exception">Exception information.</param>
        public LogEventInfo(LogLevel level, string loggerName, IFormatProvider formatProvider, [Localizable(false)] string message, object[] parameters, Exception exception)
        {
            TimeStamp = CurrentTimeGetter.Now;
            Level = level;
            LoggerName = loggerName;
            Message = message;
            Parameters = parameters;
            FormatProvider = formatProvider;
            Exception = exception;
            SequenceID = Interlocked.Increment(ref globalSequenceId);

            if (NeedToPreformatMessage(parameters))
            {
                CalcFormattedMessage();
            }
        }
示例#3
0
        private void InitAttributes()
        {
            if (!attributesLoaded)
            {
                attributesLoaded = true;
            #if !NET_CF
                foreach (DictionaryEntry de in Attributes)
                {
                    var key = (string) de.Key;
                    var value = (string) de.Value;

                    switch (key.ToUpperInvariant())
                    {
                        case "DEFAULTLOGLEVEL":
                            defaultLogLevel = LogLevel.FromString(value);
                            break;

                        case "FORCELOGLEVEL":
                            forceLogLevel = LogLevel.FromString(value);
                            break;

                        case "AUTOLOGGERNAME":
                            AutoLoggerName = XmlConvert.ToBoolean(value);
                            break;
                    }
                }
            #endif
            }
        }
示例#4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogEventInfo" /> class.
 /// </summary>
 /// <param name="level">Log level.</param>
 /// <param name="loggerName">Logger name.</param>
 /// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
 /// <param name="message">Log message including parameter placeholders.</param>
 /// <param name="parameters">Parameter array.</param>
 public LogEventInfo(LogLevel level, string loggerName, IFormatProvider formatProvider, [Localizable(false)] string message, object[] parameters)
     : this(level, loggerName, formatProvider, message, parameters, null)
 {
 }
示例#5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogEventInfo" /> class.
 /// </summary>
 /// <param name="level">Log level.</param>
 /// <param name="loggerName">Logger name.</param>
 /// <param name="message">Log message including parameter placeholders.</param>
 public LogEventInfo(LogLevel level, string loggerName, [Localizable(false)] string message)
     : this(level, loggerName, null, message, null, null)
 {
 }
示例#6
0
 /// <summary>
 ///     Creates the log event.
 /// </summary>
 /// <param name="logLevel">The log level.</param>
 /// <param name="loggerName">Name of the logger.</param>
 /// <param name="message">The message.</param>
 /// <param name="exception">The exception.</param>
 /// <returns>
 ///     Instance of <see cref="LogEventInfo" />.
 /// </returns>
 public static LogEventInfo Create(LogLevel logLevel, string loggerName, [Localizable(false)] string message, Exception exception)
 {
     return new LogEventInfo(logLevel, loggerName, null, message, null, exception);
 }
示例#7
0
 /// <summary>
 ///     Creates the log event.
 /// </summary>
 /// <param name="logLevel">The log level.</param>
 /// <param name="loggerName">Name of the logger.</param>
 /// <param name="formatProvider">The format provider.</param>
 /// <param name="message">The message.</param>
 /// <returns>
 ///     Instance of <see cref="LogEventInfo" />.
 /// </returns>
 public static LogEventInfo Create(LogLevel logLevel, string loggerName, IFormatProvider formatProvider, object message)
 {
     return new LogEventInfo(logLevel, loggerName, formatProvider, "{0}", new[] {message});
 }
示例#8
0
 /// <summary>
 ///     Creates the log event.
 /// </summary>
 /// <param name="logLevel">The log level.</param>
 /// <param name="loggerName">Name of the logger.</param>
 /// <param name="formatProvider">The format provider.</param>
 /// <param name="message">The message.</param>
 /// <param name="parameters">The parameters.</param>
 /// <returns>
 ///     Instance of <see cref="LogEventInfo" />.
 /// </returns>
 public static LogEventInfo Create(LogLevel logLevel, string loggerName, IFormatProvider formatProvider, [Localizable(false)] string message, object[] parameters)
 {
     return new LogEventInfo(logLevel, loggerName, formatProvider, message, parameters);
 }