本文整理汇总了C#中Exception.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.ToString方法的具体用法?C# Exception.ToString怎么用?C# Exception.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: traiteErreur
public string traiteErreur(System.Web.UI.Page page, String msg, Exception ex)
{
try
{
File.AppendAllText(page.Server.MapPath("App_Data'\'logErreur.txt"), "ERREUR " + DateTime.Now.ToLongDateString() + "\r\n");
File.AppendAllText(page.Server.MapPath("App_Data'\'logErreur.txt"), msg + ex.ToString());
}
catch
{
Exception ex2;
}
return "UNE ERREUR S'EST PRODUITE: " + ex.ToString();
}
示例2: HttpError
/// <summary>
/// Initializes a new instance of the <see cref="HttpError"/> class from a given <see cref="Exception"/> instance and
/// <see cref="System.Web.HttpContext"/> instance representing the HTTP context during the exception.
/// </summary>
/// <param name="e">The e.</param>
/// <param name="httpContext">The HTTP context.</param>
public HttpError(Exception e, HttpContext httpContext)
{
if (e == null)
throw new ArgumentNullException("e");
Exception = e;
// load the basic information.
var baseException = e.GetBaseException();
HostName = Environment.MachineName;
TypeName = baseException.GetType().FullName;
Message = baseException.Message;
Source = baseException.Source;
Detail = e.ToString();
UserName = (Thread.CurrentPrincipal.Identity.Name ?? string.Empty);
Date = DateTime.Now;
// if this is an http exception, then get the status code and detailed html message provided by the host.
var httpException = (e as HttpException);
if (httpException != null)
{
StatusId = httpException.GetHttpCode();
HtmlErrorMessage = (httpException.GetHtmlErrorMessage() ?? string.Empty);
}
// if the http context is available, then capture the collections that represent the state request.
if (httpContext != null)
{
var httpRequest = httpContext.Request;
ServerVariable = httpRequest.ServerVariables;
QueryString = httpRequest.QueryString;
Form = httpRequest.Form;
Cookie = httpRequest.Cookies;
}
}
示例3: HandleUnhandledException
/// <summary>
/// Logs and displays the unhandled exception message.
/// Exits the application if needed.
/// </summary>
/// <param name="ex">Exception that was thrown.</param>
/// <param name="isTerminating">Indicates whether the common language runtime is terminating.</param>
private static void HandleUnhandledException(Exception ex, bool isTerminating)
{
var errorHResult = System.Runtime.InteropServices.Marshal.GetHRForException(ex);
if (errorHResult != 0)
{
string hexValue = string.Format("{0:x}", errorHResult);
Log.Fatal("HResult: " + hexValue, ex);
}
else
{
Log.Fatal(ex);
}
try
{
MessageBox.Show(ex.ToString());
Environment.Exit(0);
}
catch
{
// re-throwing here could re-enter this handler
// causing a potentially endless loop
Log.Fatal(ex);
}
}
示例4: EmailOnException
public void EmailOnException(Exception ex,string transId)
{
try
{
logger.Debug("ThrowSoapException:EmailOnException() called");
MailMessage mail = new MailMessage();
string TO = ((NameValueCollection)System.Configuration.ConfigurationManager.GetSection("EmailConfig"))["TO"];
string FROM = ((NameValueCollection)System.Configuration.ConfigurationManager.GetSection("EmailConfig"))["FROM"];
string SUBJECT = ((NameValueCollection)System.Configuration.ConfigurationManager.GetSection("EmailConfig"))["SUBJECT"];
string DOMAIN = ((NameValueCollection)System.Configuration.ConfigurationManager.GetSection("EmailConfig"))["SMTPID"];
string PORT = ((NameValueCollection)System.Configuration.ConfigurationManager.GetSection("EmailConfig"))["PORT"];
SmtpClient smtp = new SmtpClient();
smtp.Host = DOMAIN;
smtp.Port = Convert.ToInt32(PORT);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp.EnableSsl = true;
mail.To.Add(TO);
mail.From = new MailAddress(FROM);
mail.Subject = SUBJECT;
mail.Body = "An Exception Occured At Date/Time : " + System.DateTime.Now.ToString("F") + "\n" + "Transaction ID : " + transId + "\n" + "Method Name : " + ex.TargetSite.ToString() + "\n" + "Exception Desciption :" + "\n" + ex.ToString();
smtp.Send(mail);
}
catch (Exception mailEx)
{
logger.Error(string.Format(" EmailException {0}", mailEx.Message.ToString()));
logger.Error("ThrowSoapException:EmailOnException() returning error");
//ThrowSoapException soapExp = new ThrowSoapException();
//soapExp.convertToSoapException(mailEx);
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
System.Net.WebClient wc = new System.Net.WebClient();
string eksemmelle = "";
wc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
try
{
eksemmelle = wc.DownloadString("http://www.hindu.com/rss/01hdline.xml");
}
catch (Exception e1)
{
ex = e1;
}
if (!string.IsNullOrEmpty(eksemmelle))
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(eksemmelle);
XmlNodeList list = doc.SelectNodes("rss/channel/item");
foreach (XmlNode node in list)
RenderNewsItem(node.SelectSingleNode("title").InnerText, node.SelectSingleNode("link").InnerText, node.SelectSingleNode("description").InnerText, node.SelectSingleNode("pubDate").InnerText);
}
else
{
RenderNewsItem(ex.Message,ex.ToString(),ex.Message,"121212");
}
}
示例6: GetInnerException
/// <summary>
/// 取出錯誤的相關訊息
/// </summary>
/// <param name="ex"></param>
/// <param name="Source"></param>
/// <param name="Params"></param>
/// <returns> 取出錯誤的相關訊息</returns>
/// <remarks> 取出錯誤的相關訊息</remarks>
public static string GetInnerException(Exception ex, string Source, params string[] Params)
{
StringBuilder strMsg = new StringBuilder();
StringBuilder strLogMsg = new StringBuilder();
string strKey = System.DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString("000");
string strOtherMsg = "";
if (Params.Length > 0) {
foreach (string s in Params) {
strOtherMsg += ", " + s;
}
}
if (strOtherMsg.Length > 2)
strOtherMsg = strOtherMsg.Substring(2);
strLogMsg.AppendLine(string.Format("Source:[{0}], Key={1}", Source, strKey));
if (ex is System.Data.SqlClient.SqlException) {
foreach (System.Data.SqlClient.SqlError er in ((System.Data.SqlClient.SqlException)ex).Errors) {
strLogMsg.AppendLine(er.ToString());
strMsg.AppendLine(er.Message.ToString());
}
} else {
strLogMsg.AppendLine(ex.ToString());
strMsg.AppendLine(ex.Message.ToString());
}
strMsg.AppendLine("(" + strKey + ")");
if (string.IsNullOrEmpty(strOtherMsg))
strLogMsg.AppendLine(strOtherMsg);
//WriteLog(strLogMsg.ToString(), LogType.Error)
return string.Format("[{0}]:{1}", Source, strMsg.ToString());
}
示例7: WriteToLog
public static void WriteToLog(Exception ex, string sURL, string sUserid, string sIP, string sPageURL, cbl.Syslog.Level cllevel)
{
string sErrorToFile = ex.ToString() + "| " + DateTime.Now.ToString() + "| " + sUserid + "| " + sIP + "| " + sURL;
cbl.Syslog.Client c = new cbl.Syslog.Client();
try
{
string sSysLogServer = System.Configuration.ConfigurationManager.AppSettings["SysLogServer"].ToString();
int iSysLogacility = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["SysLogFacility"]);
int isyslevel = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["SysLogLevel"]);
int level = (int)cllevel;
if (level > isyslevel)
return;
c.HostIp = sSysLogServer;
int facility = iSysLogacility;
string text = sErrorToFile;
c.Send(new cbl.Syslog.Message(facility, level, text));
}
catch (System.Exception ex1)
{
}
finally
{
c.Close();
}
}
示例8: ExceptionTraceEvent
/// <summary>
/// Initializes a new instance of the <see cref="ExceptionTraceEvent"/> class.
/// </summary>
public ExceptionTraceEvent(TraceEventType eventType, int eventId, Exception exception)
: base(eventType, eventId, new Lazy<string>(() => exception.Message + Environment.NewLine + exception.ToString()))
{
Guard.NotNull(() => exception, exception);
this.Exception = exception;
}
示例9: getException
private string getException(Exception ex)
{
var message = ex.ToString();
if (ex.InnerException != null)
message += Environment.NewLine + getException(ex.InnerException);
return message;
}
示例10: ExceptionToString
static string ExceptionToString(Exception e)
{
string ret = e.ToString();
while (true)
{
int startIndex = ret.IndexOf("[0x");
if (startIndex < 0)
{
break;
}
else
{
int endIndex = ret.IndexOf(".cs:", startIndex);
int length = endIndex - startIndex + ".cs:".Length;
ret = ret.Remove(startIndex, length);
ret = ret.Insert(startIndex, " Line:");
}
}
ret = ret.Replace("System.Collections.Generic.", "");
ret = ret.Replace("System.Reflection.", "");
ret = ret.Replace("--->", "\n --->");
return ret;
}
示例11: LogException
public static void LogException(Exception ex, bool emailAlso = true)
{
string[] logFiles = new string[]{
ConfigurationManager.AppSettings["ExceptionLogFile"]
};
LogIt(emailAlso, ex.ToString(), logFiles);
}
示例12: Log
public static void Log(Exception ex)
{
if (ex != null)
{
Log(ex.ToString());
}
}
示例13: ErrorResponse
static void ErrorResponse(HttpListenerResponse response, Int32 status, Exception e)
{
response.StatusCode = 200;
response.ContentType = "text/plain";
var content = Encoding.Unicode.GetBytes(e.ToString() + "\n");
response.AppendHeader("Content-Length", content.Length.ToString());
response.OutputStream.Write(content, 0, content.Length);
}
示例14: Log
public static void Log(Exception ex)
{
if (ex != null)
{
Log(ex.ToString());
Telemetry.TrackException(ex);
}
}
示例15: DisplayErrorInformation
private void DisplayErrorInformation(Exception exception)
{
if (exception != null)
{
lblMsg.Text = "Error";
lblError.Text = exception.Message;
lblErrorDetail.Text = exception.ToString();
}
}