.net知识点

dll版本冲突问题


    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-8.0.0.0" newVersion="4.5.0.0" />
            dependentAssembly>
        assemblyBinding>
    runtime>

动态引用外部dll

public static Assembly ass = null;//全局用于动态加载dll
        /// 
        /// 初始化log4jnet配置
        /// 
        /// 
        public static void InitConfig(string configurl)
        {
            try
            {
                //动态加载log4net的dll,并保存对象
                ass = Assembly.Load("log4net");  //加载dll文件
                Type tp = ass.GetType("log4net.Config.XmlConfigurator");//获取类名,必须命名空间+类名
                FileInfo logCfg = new FileInfo(configurl);
                tp.InvokeMember("ConfigureAndWatch", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
                                  null, null, new object[] { logCfg });


            }
            catch { }
        }

        /// 
        /// 记载http请求的相关参数
        /// 
        /// 
        /// 
        /// 
        public static void RecordHttpRequest(string url, string param, string response)
        {
            try
            {
                if (ass != null)
                {

                    Type tp = ass.GetType("log4net.LogManager");//获取类名,必须命名空间+类名
                    object logger = tp.InvokeMember("GetLogger", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
                                 null, null, new object[] { typeof(CommonUtils) });//获取log4net的对象

                    StringBuilder sb = new StringBuilder();
                    sb.Append(Environment.NewLine);
                    sb.Append("【请求的网址】:" + url + Environment.NewLine);
                    sb.Append("【请求的参数】:" + param + Environment.NewLine);
                    sb.Append("【请求的结果】:" + response + Environment.NewLine);

                    Type tpc = ass.GetType("log4net.ILog");
                    MethodInfo methc = tpc.GetMethod("Debug", new Type[] { typeof(object) });//获取方法名
                    methc.Invoke(logger, new object[] { sb.ToString() });
                }
            }
            catch { }
        }

HttpWebRequest加载证书建立SSL通道时发生异常的解决办法

<system.net>
   <settings>
      <servicePointManager
         checkCertificateName="true"
      />
   settings>
system.net>

你可能感兴趣的:(.net)