本文整理汇总了C#中System.Diagnostics.StackTrace类的典型用法代码示例。如果您正苦于以下问题:C# StackTrace类的具体用法?C# StackTrace怎么用?C# StackTrace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StackTrace类属于System.Diagnostics命名空间,在下文中一共展示了StackTrace类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetCurrentMethod
public static string GetCurrentMethod(int frame)
{
StackTrace st = new StackTrace();
StackFrame sf = st.GetFrame(frame);
return sf.GetMethod().Name;
}
开发者ID:uroskn,项目名称:LameLauncher,代码行数:7,代码来源:ConsoleLogger.cs
示例2: Eval
public override void Eval(MockDirectoryWrapper dir)
{
if (DoFail && TestThread())
{
bool isDoFlush = false;
bool isClose = false;
var trace = new StackTrace();
foreach (var frame in trace.GetFrames())
{
var method = frame.GetMethod();
if (isDoFlush && isClose)
{
break;
}
if ("flush".Equals(method.Name))
{
isDoFlush = true;
}
if ("close".Equals(method.Name))
{
isClose = true;
}
}
if (isDoFlush && !isClose && Random().NextBoolean())
{
HitExc = true;
throw new IOException(Thread.CurrentThread.Name + ": now failing during flush");
}
}
}
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:31,代码来源:TestConcurrentMergeScheduler.cs
示例3: Lock
/// <summary>
/// The object to lock.
/// </summary>
/// <param retval="o">The object to lock.</param>
/// <param retval="timeout">The timeout.</param>
/// <returns></returns>
/// <exception cref="LockTimeoutException">
/// </exception>
public static TimedLock Lock(object o, TimeSpan timeout)
{
var tl = new TimedLock(o);
if (!Monitor.TryEnter(o, timeout))
{
#if DEBUG
GC.SuppressFinalize(tl._leakDetector);
StackTrace blockingTrace;
lock (Sentinel.StackTraces)
{
blockingTrace = Sentinel.StackTraces[o] as StackTrace;
}
throw new LockTimeoutException(blockingTrace);
#else
throw new LockTimeoutException();
#endif
}
#if DEBUG
// Lock acquired. Store the stack trace.
var trace = new StackTrace();
lock (Sentinel.StackTraces)
{
Sentinel.StackTraces.Add(o, trace);
}
#endif
return tl;
}
开发者ID:gaoninggn,项目名称:NoRM,代码行数:41,代码来源:TimedLock.cs
示例4: findCallToLoadPackages
private static string findCallToLoadPackages()
{
var trace = new StackTrace(Thread.CurrentThread, false);
var frame = trace.GetFrame(2);
return "{0}.{1}(), {2} line {3}".ToFormat(frame.GetMethod().DeclaringType.FullName, frame.GetMethod().Name,
frame.GetFileName(), frame.GetFileLineNumber());
}
开发者ID:sbartlett,项目名称:fubumvc,代码行数:7,代码来源:PackageRegistry.cs
示例5: PagerState
public PagerState(AbstractPager pager)
{
_pager = pager;
#if DEBUG_PAGER_STATE
Instances[this] = new StackTrace(true);
#endif
}
开发者ID:mattwarren,项目名称:LinqToMemory,代码行数:7,代码来源:PagerState.cs
示例6: ExceptionToString
/// <summary>
/// Converts an Exception to a verbose string
/// </summary>
public static string ExceptionToString(Exception e)
{
string message;
if (object.ReferenceEquals(FormatException, null))
{
var trace = new StackTrace(e, true);
var frame = trace.GetFrame(0);
var file = frame.GetFileName();
var line = frame.GetFileLineNumber();
StringBuilder sb = new StringBuilder(String.Format("{0} line {1}", file, line));
sb.AppendLine("");
sb.AppendLine(String.Format("[Source] {0} : [Message] {1}", e.Source, e.Message));
sb.AppendLine("");
sb.AppendLine(e.ToString());
message = sb.ToString();
}
else
{
message = FormatException(e);
}
return message;
}
开发者ID:dipamchang,项目名称:tnetd-open,代码行数:29,代码来源:EventLogger.cs
示例7: CallerMethodName
public static string CallerMethodName()
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(2);
MethodBase methodBase = stackFrame.GetMethod();
return methodBase.Name;
}
开发者ID:einsteinx2,项目名称:WaveBox,代码行数:7,代码来源:ServerUtility.cs
示例8: ToCodeLocations
/// <summary>
/// Converts an exception stack to a sarif code location list.
/// </summary>
public static IList<AnnotatedCodeLocation> ToCodeLocations(this Exception exception)
{
List<AnnotatedCodeLocation> codeLocations = new List<AnnotatedCodeLocation>();
StackTrace stack = new StackTrace(exception);
foreach (StackFrame frame in stack.GetFrames())
{
AnnotatedCodeLocation codeLocation = new AnnotatedCodeLocation();
MemberInfo member = frame.GetMethod();
if (member != null)
{
codeLocation.Message = member.ReflectedType.FullName + "." + member.Name;
}
PhysicalLocationComponent physicalLocation = new PhysicalLocationComponent();
string filename = frame.GetFileName();
if (!String.IsNullOrWhiteSpace(filename))
{
physicalLocation.Uri = new Uri(filename);
}
physicalLocation.Region = new Region();
physicalLocation.Region.StartLine = frame.GetFileLineNumber();
physicalLocation.Region.EndLine = frame.GetFileLineNumber();
physicalLocation.Region.StartColumn = frame.GetFileColumnNumber();
physicalLocation.Region.EndColumn = frame.GetFileColumnNumber();
codeLocation.PhysicalLocation = new List<PhysicalLocationComponent>() { physicalLocation };
codeLocations.Add(codeLocation);
}
return codeLocations;
}
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:35,代码来源:Exception.extensions.cs
示例9: LoadReport
private void LoadReport(int memberid, string fromDate, string toDate)
{
try
{
List<ReportParameter> rp = new List<ReportParameter>();
rp.Add(new ReportParameter("MemberID", memberid.ToString()));
rp.Add(new ReportParameter("StartDate", fromDate));
rp.Add(new ReportParameter("RunDate", toDate));
//ReportViewer1.ServerReport.ReportPath = "/APT.Reports/BenefitStatement";
ReportViewer1.ServerReport.ReportPath = "/APT.Reports/APTARFInvestmentStatementWeb";
ReportViewer1.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"]);
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials(ConfigurationManager.AppSettings["ReportServerUser"], ConfigurationManager.AppSettings["ReportServerPassword"], ConfigurationManager.AppSettings["ReportServerDomain"]);
ReportViewer1.ServerReport.SetParameters(rp);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ServerReport.Refresh();
}
catch (Exception ex)
{
StackTrace stackTrace = new StackTrace();
APTLog.LogException(ex, stackTrace.GetFrame(0).GetMethod().Name, APT2012AssemblyInfo.AssemblyInfo, APT2012AssemblyInfo.SUBSYSTEM);
//throw ex;
}
}
开发者ID:ThomasJRichardson,项目名称:APT2012,代码行数:25,代码来源:ARFInvestmentStatement.aspx.cs
示例10: LogEventArgs
public LogEventArgs(string message, MessageType messageType, StackTrace st)
{
this.message = message;
this.dateTime = DateTime.Now;
this.messageType = messageType;
this.stackTrace = st;
}
开发者ID:erynet,项目名称:SensorMonitor,代码行数:7,代码来源:LogEventArgs.cs
示例11: ErrorEvent
// Methods
public ErrorEvent()
{
base.m_Severity = EventSeverity.Error;
base.m_EventID = 0x3e8;
base.m_Message = string.Format("Error in '{0}'", base.m_CallingMethod.ToString());
StringBuilder builder1 = new StringBuilder(0x3e8);
try
{
StackTrace trace1 = new StackTrace(true);
int num1 = 2;
Type type1 = null;
do
{
num1++;
type1 = trace1.GetFrame(num1).GetMethod().DeclaringType;
} while ((num1 < trace1.FrameCount) && type1.IsSubclassOf(typeof (BaseEvent)));
for (int num2 = num1; num2 < trace1.FrameCount; num2++)
{
StackFrame frame1 = trace1.GetFrame(num2);
if (num2 > num1)
{
builder1.Append('|');
}
builder1.AppendFormat("{{{0}}}:{1}:{2}", ReflectionHelper.MethodSignature(frame1.GetMethod()),
frame1.GetFileName(), frame1.GetFileLineNumber());
}
}
catch
{
}
base.AddProperty("StackTrace", builder1.ToString());
}
开发者ID:bmadarasz,项目名称:ndihelpdesk,代码行数:33,代码来源:ErrorEvent.cs
示例12: Parse
public bool Parse(StackTrace stackTrace)
{
foreach (IStackTraceParser p in GetParsers())
{
if (p.Parse(stackTrace))
{
parser = p;
return true;
}
}
var helpLink = @"http://blog.approvaltests.com/2012/01/creating-namers.html";
throw new Exception(
string.Format("Approvals is not set up to use your test framework.{0}" +
"It currently supports {1}{0}" +
"To add one use {2}.AddParser() method to add implementation of {3} with support for your testing framework.{0}" +
"To learn how to implement one see {4}",
Environment.NewLine,
ForTestingFramework,
GetType(),
typeof (IStackTraceParser),
helpLink))
{
HelpLink = helpLink
};
}
开发者ID:JakeGinnivan,项目名称:ApprovalTests.Net,代码行数:26,代码来源:StackTraceParser.cs
示例13: LogInfo
//**************************************************
// 関数名 :LogInfo
// 機能説明 :ログ情報をログファイルに書き込む。
// 引数 :logInfo ログ情報
// 引数 :args ログ詳細情報
// 修正履歴 :2010/04/13
//**************************************************
public void LogInfo(string logInfo, params object[] args)
{
string cHeader = "";
string cLogTime = "";
cLogTime = System.DateTime.Now.ToString();
if (args != null && args.Length > 0)
{
logInfo = String.Format(logInfo, args);
}
StackTrace st = new StackTrace(true);
StackFrame sf = st.GetFrame(1);
//cHeader = sf.GetMethod
cHeader = sf.GetMethod().ReflectedType.FullName + "." + sf.GetMethod().Name + "()";
cHeader = cLogTime + " [" + cHeader + "] ";
//ログ情報
logInfo = cHeader + logInfo + Environment.NewLine;
try
{
//'ログ情報はログファイルに書き込む。
File.AppendAllText(LogFileName, logInfo);
}
catch (Exception ex)
{
logInfo = String.Format("異常が発生しました。{0}", ex);
//'ログ情報はログファイルに書き込む。
File.AppendAllText(LogFileName, logInfo);
}
}
开发者ID:EWindow,项目名称:WorkGit,代码行数:37,代码来源:Logger.cs
示例14: Fail
public override void Fail (string message, string detailMessage)
{
var frames = new StackTrace (1, true).GetFrames ();
//find the stack frame that actually called into the trace system
int callerFrame = 0;
for (; (callerFrame < frames.Length && IsInfrastructureMethod (frames [callerFrame])); callerFrame++)
continue;
if (callerFrame == frames.Length - 1)
callerFrame = 0;
var sb = new StringBuilder ();
if (IsRealMessage (message)) {
if (!string.IsNullOrEmpty (detailMessage)) {
sb.AppendFormat ("Failed assertion: {0} - {1}", message, detailMessage);
} else {
sb.AppendFormat ("Failed assertion: {0}", message);
}
} else {
sb.Append ("Failed assertion at ");
FormatStackFrame (sb, frames [callerFrame]);
callerFrame++;
}
sb.Append ("\n");
FormatStackTrace (sb, frames, callerFrame);
LoggingService.LogError (sb.ToString ());
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:29,代码来源:AssertLoggingTraceListener.cs
示例15: Tracer
/// <summary>
/// Initializes a new instance of the <see cref="Tracer"/> class.
/// Results in a method entry trace being output.
/// </summary>
public Tracer()
{
if (!_isTracingEnabled)
{
return;
}
// Due to optimizations during JIT compilation the StackTrace and its properties are not reliable
// especially when the following code is in a separate method
// http://www.smelser.net/blog/2008/11/default.aspx
_numberOfCallingMethodParams = 0;
_callingMethodName = "Not available";
StackTrace stackTrace = new StackTrace();
StackFrame callingMethodFrame = stackTrace.GetFrame(1);
if (callingMethodFrame != null)
{
MethodBase methodInfo = callingMethodFrame.GetMethod();
if (methodInfo != null)
{
ParameterInfo[] parameterInfo = methodInfo.GetParameters();
_numberOfCallingMethodParams = parameterInfo.Count();
Type declaringType = methodInfo.DeclaringType;
if (declaringType != null)
{
_callingMethodName = declaringType.Name + "." + methodInfo.Name;
}
}
}
TraceMethodEntry(null);
}
开发者ID:jsuurd,项目名称:dxa-web-application-dotnet,代码行数:38,代码来源:Tracer.cs
示例16: gvContributions_RowDataBound
protected void gvContributions_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType != DataControlRowType.Header)
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (drv != null)
{
Object dateVal = drv["DateReceived"];
if (!Convert.IsDBNull(dateVal))
{
e.Row.Attributes.Add("onclick", "GetContributions('" + dateVal.ToString() + "');");
}
}
e.Row.Attributes.Add("onmouseover", "highlight(this, true);");
e.Row.Attributes.Add("onmouseout", "highlight(this, false);");
e.Row.Attributes.Add("onmouseup", "selectedRow(this);");
}
}
catch (Exception ex)
{
StackTrace stackTrace = new StackTrace();
APTLog.LogException(ex, stackTrace.GetFrame(0).GetMethod().Name, APT2012AssemblyInfo.AssemblyInfo, APT2012AssemblyInfo.SUBSYSTEM);
//throw ex;
}
}
开发者ID:ThomasJRichardson,项目名称:APT2012,代码行数:27,代码来源:Contributions.aspx.cs
示例17: LogInfo
public static void LogInfo(Exception ex)
{
try
{
//Writes error information to the log file including name of the file, line number & error message description
//Console.WriteLine("Start");
stackTrace = new StackTrace(ex, true);
//Console.WriteLine("Frames: {0}", stackTrace.FrameCount);
//Console.WriteLine("Frame 0: {0}", stackTrace.GetFrame(0).GetFileName());
//string fileNames = stackTrace.GetFrame((stackTrace.FrameCount - 1)).GetFileName();
//Console.WriteLine(fileNames);
//fileNames = fileNames.Substring(fileNames.LastIndexOf(Application.ProductName));
//Console.WriteLine("Rawr");
//Int32 lineNumber = stackTrace.GetFrame((stackTrace.FrameCount - 1)).GetFileLineNumber();
//Console.WriteLine(lineNumber);
methodBase = stackTrace.GetFrame((stackTrace.FrameCount - 1)).GetMethod(); //These two lines are respnsible to find out name of the method
String methodName = methodBase.Name;
Info("Error in method " + methodName + ". Message: " + ex.Message);
//Info("Error in " + fileNames + ". Method name is " + methodName + ", at line number " + lineNumber.ToString() + ". Error Message: " + ex.Message);
}
catch (Exception genEx)
{
Info(genEx.Message);
Log.LogInfo(genEx);
}
finally
{
Dispose();
}
}
开发者ID:nekosaur,项目名称:FirstStrikeLauncher,代码行数:34,代码来源:Log.cs
示例18: OutputStack
public static string OutputStack()
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame;
MethodBase stackFrameMethod;
string typeName = string.Empty;
string newTypeName;
StringBuilder sb = null;
sb = new StringBuilder();
int position = 0;
for (int x = position; x < stackTrace.FrameCount; x++)
{
stackFrame = stackTrace.GetFrame(x);
stackFrameMethod = stackFrame.GetMethod();
newTypeName = stackFrameMethod.ReflectedType.FullName;
if (newTypeName != typeName)
{
sb.AppendLine();
sb.AppendLine(newTypeName);
typeName = newTypeName;
}
sb.Append(stackFrameMethod);
sb.Append(" ");
}
return sb.ToString();
}
开发者ID:nka1,项目名称:Daytona,代码行数:32,代码来源:Utils.cs
示例19: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
int selectedSchemeId = (int)Session["SelectedSchemeId"];
int selectedEmployeeId = (int)Session["SelectedEmployeeId"];
List<ReportParameter> rp = new List<ReportParameter>();
rp.Add(new ReportParameter("SchemeId", selectedSchemeId.ToString()));
rp.Add(new ReportParameter("Currency", Employer.GetCurrency(selectedEmployeeId)));
ReportViewer1.ServerReport.ReportPath = "/APT.Reports/TrusteeSchemeMemberContributionRates";
ReportViewer1.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"]);
ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials(ConfigurationManager.AppSettings["ReportServerUser"], ConfigurationManager.AppSettings["ReportServerPassword"], ConfigurationManager.AppSettings["ReportServerDomain"]);
ReportViewer1.ServerReport.SetParameters(rp);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ServerReport.Refresh();
}
}
catch (Exception ex)
{
StackTrace stackTrace = new StackTrace();
APTLog.LogException(ex, stackTrace.GetFrame(0).GetMethod().Name, APT2012AssemblyInfo.AssemblyInfo, APT2012AssemblyInfo.SUBSYSTEM);
//throw ex;
}
}
开发者ID:ThomasJRichardson,项目名称:APT2012,代码行数:29,代码来源:TrusteeContributionRates.aspx.cs
示例20: WriteStackTrace
/// <summary>
/// 全スレッドのスタックトレースを出力します。
/// </summary>
public void WriteStackTrace()
{
var threads = Process.GetCurrentProcess().Threads;
foreach (var th in threads)
{
var thread = th as Thread;
if (thread == null)
{
continue;
}
var stackTrace = new StackTrace(thread, true);
var strBuilder = new StringBuilder();
strBuilder.AppendLine("StackTrace:");
foreach (var frame in StackTraceUtil.ToStackTraceString(stackTrace))
{
strBuilder.AppendFormat(
" {0}",
frame);
strBuilder.AppendLine();
}
Log.Info("begin lock {0}{1}{2}",
this.lockId,
Environment.NewLine,
strBuilder.ToString());
}
}
开发者ID:JuroGandalf,项目名称:Ragnarok,代码行数:34,代码来源:DebugLock.cs
注:本文中的System.Diagnostics.StackTrace类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论