示例#1
0
        public void Log <TState>(ML.LogLevel logLevel, ML.EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var msg = formatter(state, exception);

            switch (logLevel)
            {
            case ML.LogLevel.Critical:
                logger.Fatal(msg);
                return;

            case ML.LogLevel.Debug:
                logger.Debug(msg);
                return;

            case ML.LogLevel.Error:
                logger.Error(msg);
                return;

            case ML.LogLevel.Information:
                logger.Info(msg);
                return;

            case ML.LogLevel.Trace:
                logger.Trace(msg);
                return;

            case ML.LogLevel.Warning:
                logger.Warn(msg);
                return;
            }
        }
示例#2
0
 private static void LogPrint(LoggingCommon.ILog log)
 {
     log.Info("info message");
     log.Error(new InvalidDataException("just testing"));
     log.Debug("debug message");
     log.Warn("warn message");
     log.Error("error message");
     log.Fatal("fatal message");
 }
示例#3
0
        /// <summary>
        /// 消息輸出
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="level">級別</param>
        /// <param name="exception">異常對象</param>
        public void Output(string message, MessageLevel level, Exception exception)
        {
            Common.Logging.ILog logger = LogManager.GetLogger(GetType());
            switch (level)
            {
            case MessageLevel.Trace:
                if (logger.IsTraceEnabled)
                {
                    logger.Trace(message, exception);
                }
                break;

            case MessageLevel.Debug:
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(message, exception);
                }
                break;

            case MessageLevel.Info:
                if (logger.IsInfoEnabled)
                {
                    logger.Info(message, exception);
                }
                break;

            case MessageLevel.Warn:
                if (logger.IsWarnEnabled)
                {
                    logger.Warn(message, exception);
                }
                break;

            case MessageLevel.Error:
                if (logger.IsErrorEnabled)
                {
                    logger.Error(message, exception);
                }
                break;

            case MessageLevel.Fatal:
                if (logger.IsFatalEnabled)
                {
                    logger.Fatal(message, exception);
                }
                break;
            }
        }
        public static void LogEx(this Common.Logging.ILog log, Common.Logging.LogLevel level, Action <TraceRecord> traceAction, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
        {
            // Check if this log level is enabled
            if (level == LogLevel.Trace && log.IsTraceEnabled == false ||
                level == LogLevel.Debug && log.IsDebugEnabled == false ||
                level == LogLevel.Info && (log.IsInfoEnabled == false) ||
                level == LogLevel.Warn && (log.IsWarnEnabled == false) ||
                level == LogLevel.Error && (log.IsErrorEnabled == false) ||
                level == LogLevel.Fatal && (log.IsFatalEnabled == false))
            {
                return;
            }

            TraceRecord tr = new TraceRecord()
            {
                Level = level
            };

            traceAction(tr);
            string message = String.Format("{0}() line {1}: {2}.{3}", member, line, tr.Message, (tr.Data != null) ? Newtonsoft.Json.JsonConvert.SerializeObject(tr.Data) : "");

            switch (level)
            {
            case LogLevel.Trace: log.Trace(message, tr.Exception); break;

            case LogLevel.Debug: log.Debug(message, tr.Exception); break;

            case LogLevel.Error: log.Error(message, tr.Exception); break;

            case LogLevel.Fatal: log.Fatal(message, tr.Exception); break;

            case LogLevel.Info: log.Info(message, tr.Exception); break;

            case LogLevel.Warn: log.Warn(message, tr.Exception); break;
            }
        }
示例#5
0
 public void Fatal(object obj)
 {
     _log.Fatal(obj);
 }
示例#6
0
 /// <summary>
 /// Log a message string with the Fatal level.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Fatal(string message)
 {
     _logger.Fatal(message);
 }