private void WriteLog(MsmqMessage message) { try { string strFilePath = System.Web.HttpContext.Current.Server.MapPath("../log/" + System.DateTime.Now.ToString("yyyy-MM-dd") + "_Message.txt");//此处路径一定要确保log文件夹存在 if (File.Exists(strFilePath) == false) { using (File.Create(strFilePath)) { } } using (System.IO.FileStream fs = new System.IO.FileStream(strFilePath, System.IO.FileMode.Append)) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.Default)) { System.Xml.Serialization.XmlSerializer xz = new System.Xml.Serialization.XmlSerializer(message.GetType()); xz.Serialize(sw, message.GetType()); sw.WriteLine(sw.ToString()); } } } catch (Exception ex) { }