public static string GetValueFromXML(string nodeName, string arrtiName) { string strRet = ""; try { XmlDocument doc = new XmlDocument(); string strPath = AppDomain.CurrentDomain.BaseDirectory + @"bin\NetConfig.xml"; doc.Load(strPath); XmlElement rootElem = doc.DocumentElement; XmlNode node = rootElem.SelectSingleNode("//" + nodeName); XmlNodeList lstNodes = node.ChildNodes; foreach (XmlNode v in lstNodes) { if (v.Attributes["isused"].Value == "1") { strRet = v.Attributes[arrtiName].Value; break; } } } catch (Exception ex) { strRet = @"data source=JCX-server\localdb;initial catalog=IVS30;persist security info=True;user id=sa;password=; MultipleActiveResultSets=true;"; #region 日志记录 string strCategory = Log.LogType.NetFail.ToString(); LOG_INFO logInfo = new LOG_INFO(); logInfo.Category = strCategory; logInfo.HostName = System.Net.Dns.GetHostName(); logInfo.IPAddress = Log.GetIPAddress(logInfo.HostName); logInfo.LogTime = DateTime.Now; logInfo.FS_Infor = ""; logInfo.JS_Infor = ""; logInfo.Log_Infor = "查找配置文件出错:配置文件路径为" + AppDomain.CurrentDomain.BaseDirectory + @"\bin\NetConfig.xml" + "错误消息为:" + ex.Message; logInfo.Name = "读取配置文件"; logInfo.FunName = "ReadConfig.cs -> GetValueFromXML(" + nodeName + "," + arrtiName + ")"; Log.WriteLog(logInfo); #endregion } return(strRet); }
public static bool WriteLog(LOG_INFO logInfo) { return(true); //bool bolResult = false; //string strSql = "insert into LOG_INFO(JCLSH,Category,Name,FS_Infor,JS_Infor,Log_Infor,FunName,LogTime) "; //strSql += " values('" + logInfo.JCLSH + "','" + logInfo.Category + "','" + logInfo.Name + "','" + logInfo.FS_Infor + "','" + logInfo.JS_Infor + "','" + logInfo.Log_Infor + "','" + logInfo.FunName + "','" + logInfo.LogTime.ToString("yyyy-MM-dd HH:mm:ss") + "')"; //try //{ // string strConn = ReadConfig.GetValueFromXML("connectionString", "value"); // SqlConnection conn = new SqlConnection(strConn); // conn.Open(); // if (conn.State == ConnectionState.Open) // { // SqlCommand m_cmdCommand = conn.CreateCommand(); // m_cmdCommand.Parameters.Clear(); // m_cmdCommand.CommandType = CommandType.Text; // m_cmdCommand.CommandText = strSql; // try // { // m_cmdCommand.ExecuteNonQuery(); // bolResult = true; // } // catch // { // } // finally // { // m_cmdCommand.Dispose(); // conn.Close(); // } // } //} //catch (Exception ex) //{ //} //return bolResult; }