Ejemplo n.º 1
0
        /// <summary>
        /// 获得默认的字符串加密、解密对象。在Web.config的AppSetting中通过site.security.encryption.provider指定类的全名。
        /// </summary>
        /// <returns>AbstractStringEncryptor对象实例。可能有异常发生。</returns>
        public static AbstractStringEncryptor GetDefaultEncryptor()
        {
            Conf   conf = Conf.CreateFromWebConfig();
            string type = conf.get("site.security.encryption.provider") as string;

            if (string.IsNullOrEmpty(type))
            {
                type = "Helper.DES";
                // log ...
                AbstractLogger.GetLogger(typeof(AbstractStringEncryptor)).Warn("未配置site.security.encryption.provider,将使用“Helper.DES”类作为字符串加密、解密工具。");
            }
            return(GetEncryptor(type));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获得实现AbstractLogger的类的实例,类的名称在Web.config中指定(默认返回Helper.FileLogger的实例)。此类必须在Helper命名空间下,可以参考Helper.FileLogger。
        /// </summary>
        /// <param name="tLogFor">为其提供Logging服务的Type,一般是某个页面的this.GetType()</param>
        /// <param name="strClassFullName">实现AbstractLogger的类的全名</param>
        /// <returns>成功时返回Logger实例,否则null。可能有异常抛出。</returns>
        public static AbstractLogger GetLogger(Type typeLogFor, string strLoggerClassFullName)
        {
            AbstractLogger _l = null;

            lock (_htInstances)
            {
                if (_htInstances.ContainsKey(typeLogFor.FullName))
                {
                    _l            = _htInstances[typeLogFor.FullName] as AbstractLogger;
                    _l.TypeLogFor = typeLogFor;
                    return(_l);
                }
                return((_htInstances[typeLogFor.FullName] = Activator.CreateInstance(Type.GetType(strLoggerClassFullName, true), new object[] { typeLogFor }))
                       as AbstractLogger);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 以DEBUG级别将信息输出到文件日志
 /// </summary>
 /// <param name="strMsg">要输出的信息</param>
 /// <param name="req">当前的请求对象,可以为null</param>
 public static void LogError(string strMsg, HttpContext context)
 {
     try
     {
         // get the default FileLogger instance
         AbstractLogger logger = AbstractLogger.GetLogger(typeof(Function));
         if (logger == null)
         {
             return;
         }
         logger.Error(
             string.Format("[{0}] by [{1}]\r\n{2}\r\n",
                           context == null ? "N/A" : context.Request.RawUrl,
                           context == null ? "N/A" : context.Request.UserHostAddress,
                           strMsg));
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Assert(false, ex.Message);
     }
 }