public static void CustomErrorLog(Exception exception) { CustomException customException = null; if (exception.GetType() == typeof(CustomException)) { customException = (CustomException)exception; } else if (exception.InnerException != null && exception.InnerException.GetType() == typeof(CustomException)) { customException = (CustomException)exception.InnerException; } else { customException = new CustomException(CustomExceptionType.CommonUnhandled, string.Empty, exception); } string errorMessage = customException.GetDefaultMessage(customException.ExceptionType); errorMessage = Format(null, customException.ExceptionType.ToString(), errorMessage, customException.UserDefinedMessage, customException.SystemDefinedMessage, customException.InnerException); }
public byte[] GetSerializedContent() { try { StringBuilder xmlContent = new StringBuilder(); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Encoding = Encoding.UTF8; xmlWriterSettings.CloseOutput = true; xmlWriterSettings.OmitXmlDeclaration = true; XmlWriter xmlWriter = XmlWriter.Create(xmlContent, xmlWriterSettings); xmlWriter.WriteStartElement("CustomException"); xmlWriter.WriteElementString("ExceptionType", this.ExceptionType.ToString()); xmlWriter.WriteElementString("ExceptionPriority", this.ExceptionPriority.ToString()); xmlWriter.WriteStartElement("UserMessage"); xmlWriter.WriteCData(this.Message); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("SystemMessage"); xmlWriter.WriteCData(this.SystemDefinedMessage); xmlWriter.WriteEndElement(); Exception innerException = this.InnerException; int innerExceptionCount = 0; while (innerException != null) { innerExceptionCount++; xmlWriter.WriteStartElement("InnerException"); xmlWriter.WriteElementString("Message", innerException.Message); xmlWriter.WriteElementString("Source", innerException.Source); xmlWriter.WriteElementString("StackTrace", innerException.StackTrace); innerException = innerException.InnerException; } for (int i = 0; i < innerExceptionCount; i++) { xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); xmlWriter.Flush(); xmlWriter.Close(); return Encoding.UTF8.GetBytes(xmlContent.ToString()); } catch (Exception ex) { CustomException newException = new CustomException(CustomExceptionType.CommonSerialization, "Error While Serialization Of Exception", ex); ExceptionHelper.Manage(newException); } return default(byte[]); }