Beispiel #1
0
        /// <summary>
        /// 记录异常日志
        /// </summary>
        /// <param name="context">日志上下文</param>
        public static void LogException(ExceptionLogContext context)
        {
            try
            {
                Logger logger = NLog.LogManager.GetLogger("Error");

                if (ConfigurationManager.LoggingEnable && logger.IsErrorEnabled)
                {
                    LogEventInfo log = new LogEventInfo(LogLevelConverter.Convert(context.Level), "", "");

                    log.Properties["type"] = context.Type;
                    log.Properties["url"] = context.RequestUrl;
                    log.Properties["referer"] = context.RefererUrl;
                    log.Properties["controller"] = context.Controller;
                    log.Properties["action"] = context.Action;
                    log.Properties["username"] = context.Username;
                    log.Properties["userip"] = context.UserIP;
                    log.Properties["useragent"] = context.UserAgent;
                    log.Message = context.Message;
                    log.Exception = context.Exception;
                    log.TimeStamp = context.TimeStamp;

                    logger.Log(log);
                }
            }
            catch { }
        }
Beispiel #2
0
        /// <summary>
        /// 记录异常日志
        /// </summary>
        /// <param name="context">日志上下文</param>
        public static void LogException(ExceptionLogContext context)
        {
            try
            {
                Logger logger = NLog.LogManager.GetLogger("Error");

                if (ConfigurationManager.LoggingEnable && logger.IsErrorEnabled)
                {
                    LogEventInfo log = new LogEventInfo(LogLevelConverter.Convert(context.Level), "", "");

                    log.Properties["type"]       = context.Type;
                    log.Properties["url"]        = context.RequestUrl;
                    log.Properties["referer"]    = context.RefererUrl;
                    log.Properties["controller"] = context.Controller;
                    log.Properties["action"]     = context.Action;
                    log.Properties["username"]   = context.Username;
                    log.Properties["userip"]     = context.UserIP;
                    log.Properties["useragent"]  = context.UserAgent;
                    log.Message   = context.Message;
                    log.Exception = context.Exception;
                    log.TimeStamp = context.TimeStamp;

                    logger.Log(log);
                }
            }
            catch { }
        }