private static void WriteException(WcfInvokeInfo invokeInfo, Exception ex) { var logWriter = LogWriterGetter.GetLogWriter(); if (logWriter != null) { for (int i = 0; i < invokeInfo.Parameters.Length; i++) { if (invokeInfo.Parameters[i] != null) { ex.Data.Add("[" + i + "]" + invokeInfo.Parameters[i].GetType().Name, "值:" + invokeInfo.Parameters[i]); } } logWriter.Write("Error", invokeInfo.MethodName, ex); } }
private static void WriteLog(WcfInvokeInfo invokeInfo, int time) { var logWriter = LogWriterGetter.GetLogWriter(); if (logWriter != null) { var sb = new StringBuilder(); if (invokeInfo != null) { sb.AppendLine("执行函数:" + invokeInfo.MethodName); foreach (var p in invokeInfo.Parameters) { if (p != null) { sb.AppendLine(string.Format(" 参数类型:{0};值:{1}", p.GetType().Name, p)); } } } logWriter.Write("Timeout\\Info-", invokeInfo.MethodName + "_" + time, LogType.Information, invokeInfo.MethodName + "_" + time, sb.ToString()); } }
/// <summary> /// 取得客户端真实IP。如果有代理则取第一个非内网地址 /// </summary> //public static string IPAddress //{ // get // { // var x_forwarded = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; // var remote = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; // string result = string.Empty; // if (!string.IsNullOrEmpty(x_forwarded)) // { // result = x_forwarded; // //可能有代理 // if (result.IndexOf(".") == -1) //没有“.”肯定是非IPv4格式 // result = string.Empty; // else // { // if (result.IndexOf(",") != -1) // { // //有“,”,估计多个代理。取第一个不是内网的IP。 // result = result.Replace(" ", "").Replace("'", ""); // string[] temparyip = result.Split(",;".ToCharArray()); // for (int i = 0; i < temparyip.Length; i++) // { // if (ValidateHelper.IsIPAddress(temparyip[i]) // && temparyip[i].Substring(0, 3) != "10." // && temparyip[i].Substring(0, 7) != "192.168" // && temparyip[i].Substring(0, 7) != "172.16.") // { // return temparyip[i]; //找到不是内网的地址 // } // } // } // else if (ValidateHelper.IsIPAddress(result)) //代理即是IP格式 ,IsIPAddress判断是否是IP的方法, // return result; // else // result = string.Empty; //代理中的内容 非IP,取IP // } // } // if (string.IsNullOrEmpty(result)) // result = remote; // if (string.IsNullOrEmpty(result)) // result = HttpContext.Current.Request.UserHostAddress; // if (string.IsNullOrEmpty(result) || result == "::1") // result = "127.0.0.1"; // return result; // } //} /// <summary> /// 获取ip的名称 /// </summary> public static IpInfo GetIpDisplayname_Sina(string ip) { if (string.IsNullOrEmpty(ip)) { return(new IpInfo()); } var json = Common.Net.PostManager.Get(string.Format("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip={0}", ip), Encoding.UTF8); try { //json = json.Substring(json.IndexOf('{')).TrimEnd(';'); var obj = JsonSerializer.Deserialize <IpInfo>(json); return(obj); } catch (Exception ex) { ex = new Exception("获取IP出错 - IP:" + ip + ";JSON结果:" + json, ex); LogWriterGetter.GetLogWriter().Write("Error", "GetIpDisplayname_Sina", ex); } return(null); }