本文整理汇总了C#中System.Exception.TryGetCallerInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.TryGetCallerInfo方法的具体用法?C# Exception.TryGetCallerInfo怎么用?C# Exception.TryGetCallerInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.TryGetCallerInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Error
/// <summary>
/// Initializes a new instance of the <see cref="Error"/> class
/// from a given <see cref="Exception"/> instance and
/// <see cref="HttpContext"/> instance representing the HTTP
/// context during the exception.
/// </summary>
public Error(Exception e, HttpContextBase context)
{
if (e == null)
throw new ArgumentNullException("e");
_exception = e;
Exception baseException = e.GetBaseException();
//
// Load the basic information.
//
_hostName = Environment.TryGetMachineName(context);
_typeName = baseException.GetType().FullName;
_message = baseException.Message;
_source = baseException.Source;
_detail = e.ToString();
_user = Thread.CurrentPrincipal.Identity.Name ?? string.Empty;
_time = DateTime.Now;
//
// If this is an HTTP exception, then get the status code
// and detailed HTML message provided by the host.
//
HttpException httpException = e as HttpException;
if (httpException != null)
{
_statusCode = httpException.GetHttpCode();
_webHostHtmlMessage = TryGetHtmlErrorMessage(httpException) ?? string.Empty;
}
//
// If the HTTP context is available, then capture the
// collections that represent the state request as well as
// the user.
//
if (context != null)
{
IPrincipal webUser = context.User;
if (webUser != null
&& (webUser.Identity.Name ?? string.Empty).Length > 0)
{
_user = webUser.Identity.Name;
}
var request = context.Request;
var qsfc = request.TryGetUnvalidatedCollections((form, qs, cookies) => new
{
QueryString = qs,
Form = form,
Cookies = cookies,
});
_serverVariables = CopyCollection(request.ServerVariables);
// patch to include raw URL so error reports are useful when URL rewriting (isite/dvanderwilt)
_serverVariables.Add("RAW_URL", context.Request.RawUrl);
_queryString = CopyCollection(qsfc.QueryString);
_form = CopyCollection(qsfc.Form);
_cookies = CopyCollection(qsfc.Cookies);
}
var callerInfo = e.TryGetCallerInfo() ?? CallerInfo.Empty;
if (!callerInfo.IsEmpty)
{
_detail = "# caller: " + callerInfo
+ System.Environment.NewLine
+ _detail;
}
}
示例2: Error
/// <summary>
/// Initializes a new instance of the <see cref="Error"/> class
/// from a given <see cref="Exception"/> instance and
/// <see cref="HttpContext"/> instance representing the HTTP
/// context during the exception.
/// </summary>
public Error(Exception e, HttpContextBase context)
{
if (e == null)
throw new ArgumentNullException("e");
_exception = e;
Exception baseException = e.GetBaseException();
//
// Load the basic information.
//
_hostName = Environment.TryGetMachineName(context);
_typeName = baseException.GetType().FullName;
_message = baseException.Message;
_source = baseException.Source;
_detail = e.ToString();
_user = Thread.CurrentPrincipal.Identity.Name ?? string.Empty;
_time = DateTime.Now;
//
// If this is an HTTP exception, then get the status code
// and detailed HTML message provided by the host.
//
HttpException httpException = e as HttpException;
if (httpException != null)
{
_statusCode = httpException.GetHttpCode();
_webHostHtmlMessage = TryGetHtmlErrorMessage(httpException) ?? string.Empty;
}
//
// If the HTTP context is available, then capture the
// collections that represent the state request as well as
// the user.
//
if (context != null)
{
IPrincipal webUser = context.User;
if (webUser != null
&& (webUser.Identity.Name ?? string.Empty).Length > 0)
{
_user = webUser.Identity.Name;
}
var request = context.Request;
var qsfc = request.TryGetUnvalidatedCollections((form, qs, cookies) => new
{
QueryString = qs,
Form = form,
Cookies = cookies,
});
_serverVariables = CopyCollection(request.ServerVariables);
if (_serverVariables != null)
{
// Hack for issue #140:
// http://code.google.com/p/elmah/issues/detail?id=140
const string authPasswordKey = "AUTH_PASSWORD";
string authPassword = _serverVariables[authPasswordKey];
if (authPassword != null) // yes, mask empty too!
_serverVariables[authPasswordKey] = "*****";
}
_queryString = CopyCollection(qsfc.QueryString);
_form = CopyCollection(qsfc.Form);
_cookies = CopyCollection(qsfc.Cookies);
// Adding total bytes of request to output, sometimes this doesn't match
// the bytes sent in the header
_serverVariables.Add("TOTAL_BYTES", request.TotalBytes.ToString());
// re-read the raw input from the request and put it into the output
try
{
System.IO.Stream inputStream = request.InputStream;
inputStream.Position = 0;
using (System.IO.StreamReader reader = new System.IO.StreamReader(inputStream))
{
_serverVariables.Add("RAW_INPUT_STREAM", reader.ReadToEnd());
}
}
catch (Exception) { }
}
var callerInfo = e.TryGetCallerInfo() ?? CallerInfo.Empty;
if (!callerInfo.IsEmpty)
{
_detail = "# caller: " + callerInfo
//.........这里部分代码省略.........
示例3: Error
/// <summary>
/// Initializes a new instance of the <see cref="Error"/> class
/// from a given <see cref="Exception"/> instance and
/// <see cref="HttpContext"/> instance representing the HTTP
/// context during the exception.
/// </summary>
public Error(Exception e, HttpContextBase context)
{
if (e == null)
throw new ArgumentNullException("e");
_exception = e;
var baseException = e.GetBaseException();
//
// Load the basic information.
//
try
{
_hostName = Environment.MachineName;
}
catch (SecurityException)
{
// A SecurityException may occur in certain, possibly
// user-modified, Medium trust environments.
_hostName = string.Empty;
}
_typeName = baseException.GetType().FullName;
_message = baseException.Message;
_source = baseException.Source;
_detail = e.ToString();
_user = Thread.CurrentPrincipal.Identity.Name ?? string.Empty;
_time = 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)
{
_statusCode = httpException.GetHttpCode();
_webHostHtmlMessage = TryGetHtmlErrorMessage(httpException) ?? string.Empty;
}
//
// If the HTTP context is available, then capture the
// collections that represent the state request as well as
// the user.
//
if (context != null)
{
var webUser = context.User;
if (webUser != null
&& (webUser.Identity.Name ?? string.Empty).Length > 0)
{
_user = webUser.Identity.Name;
}
var request = context.Request;
var qsfc = request.TryGetUnvalidatedCollections((form, qs, cookies) => new
{
QueryString = qs,
Form = form,
Cookies = cookies,
});
_serverVariables = CopyCollection(request.ServerVariables);
_queryString = CopyCollection(qsfc.QueryString);
_form = CopyCollection(qsfc.Form);
_cookies = CopyCollection(qsfc.Cookies);
}
var callerInfo = e.TryGetCallerInfo() ?? CallerInfo.Empty;
if (!callerInfo.IsEmpty)
{
_detail = "# caller: " + callerInfo
+ System.Environment.NewLine
+ _detail;
}
}