/// <summary> /// сериализует исключение в xml - строку /// </summary> /// <param name="ex">Исключение</param> /// <returns></returns> public static string Serialize(ExceptionToXMLBuider ex) { if (ex == null) { throw new ArgumentNullException(); } string path = @"exception.xml"; string res = null; TextWriter wr = new StreamWriter(new MemoryStream()); using (TextWriter writer = new StreamWriter(new MemoryStream())) { XmlSerializer serializer = new XmlSerializer(typeof(ExceptionToXMLBuider)); serializer.Serialize(writer, ex); } using (StreamReader reader = new StreamReader(path)) { res = reader.ReadToEnd(); } File.Delete(path); return res; }
/// <summary> /// отправка сообщения об ошибке /// </summary> /// <param name="ex"></param> /// <param name="client"></param> public static void SendError(TcpClient client, Exception ex) { ExceptionToXMLBuider exception= new ExceptionToXMLBuider(ex); string msg = ExceptionToXMLBuider.Serialize(exception); Write(client,msg); }