public static void WriteLog(string logType, string logSource, LogSeverityEnum logSeverityEnum, string logContent, string logOperator) { if (_systemLog == false) { return; } // string hostName = String.Empty; string hostIP = String.Empty; string hostMac = String.Empty; if (string.IsNullOrEmpty(_systemArchitectureType)) { throw new Exception("系统配置项[SystemArchitectureType]配置有误,请联系管理员!"); } else if (_systemArchitectureType.ToUpper() == "CS") { hostName = System.Environment.UserDomainName + "\\" + System.Environment.MachineName; // System.Net.IPAddress[] addressList = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList; for (int i = 0; i < addressList.Length; i++) { if (addressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { hostIP += ":" + addressList[i].ToString(); } } hostIP = hostIP.TrimStart(':'); // System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration"); System.Management.ManagementObjectCollection moc = mc.GetInstances(); foreach (System.Management.ManagementObject mo in moc) { if (mo["IPEnabled"].ToString() == "True") { hostMac = mo["MacAddress"].ToString(); break; } } } else if (_systemArchitectureType.ToUpper() == "BS") { hostName = System.Web.HttpContext.Current.Request.UserHostName; hostIP = System.Web.HttpContext.Current.Request.UserHostAddress; } else { throw new Exception("系统配置项[SystemArchitectureType]配置有误,请联系管理员!"); } SSLogManager.WriteLog(logType, logSource, logSeverityEnum, logContent, logOperator, hostName, hostIP, hostMac); }
public static void WriteLog(string logType, string logSource, LogSeverityEnum logSeverityEnum, string logContent, string logOperator, string hostName, string hostIP, string hostMac) { if (_systemLog == false) { return; } // CO_SYSTEM_LOG log = new CO_SYSTEM_LOG(); log.LogGuid = Guid.NewGuid(); log.LogType = logType; log.LogSource = logSource; log.LogSeverity = Convert.ToInt32(logSeverityEnum); log.LogContent = logContent; log.LogDate = DAO.UtilDAO.GetDatabaseDatetime(); log.LogDateUtc = DAO.UtilDAO.GetDatabaseUtcDatetime(); log.LogOperator = logOperator; log.HostName = hostName; log.HostIP = hostIP; log.HostMac = hostMac; SSLogManager.WriteLog(log); }