本文整理汇总了C#中System.Diagnostics.StackTrace.GetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# StackTrace.GetMethod方法的具体用法?C# StackTrace.GetMethod怎么用?C# StackTrace.GetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackTrace
的用法示例。
在下文中一共展示了StackTrace.GetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayTestResults
protected static void DisplayTestResults(RunSummary summary)
{
var caller =
new StackTrace().GetFrames()
.First(f => typeof(NServiceBusPerformanceTest).IsAssignableFrom(f.GetMethod().DeclaringType.BaseType));
var testCategory =
caller.GetMethod()
.DeclaringType.Namespace.Replace(typeof(NServiceBusPerformanceTest).Namespace + ".", "");
var testCase = caller.GetMethod().Name;
var c = (PerformanceTestContext)summary.RunDescriptor.ScenarioContext;
var messagesPerSecondsProcessed = c.NumberOfTestMessages/
(c.LastMessageProcessedAt - c.FirstMessageProcessedAt).TotalSeconds;
Console.Out.WriteLine("Results: {0} messages, {1} msg/s", c.NumberOfTestMessages,
messagesPerSecondsProcessed);
using (var file = new StreamWriter(".\\PerformanceTestResults.txt", true))
{
file.WriteLine(string.Join(";", summary.RunDescriptor.Key, testCategory, testCase,
c.NumberOfTestMessages, messagesPerSecondsProcessed));
}
Console.Out.WriteLine("##teamcity[buildStatisticValue key='{0}' value='{1:0}']",
summary.RunDescriptor.Key + "." + testCategory + "." + testCase, messagesPerSecondsProcessed);
}
示例2: LogMethodExit
public static void LogMethodExit(
LOGSEVERITY eSeverity = LOGSEVERITY.Information)
{
var sf = new StackTrace(true).GetFrame(1);
var method = sf.GetMethod();
Log("exit.", eSeverity, sf.GetMethod().Name, sf.GetFileLineNumber(), method.ReflectedType.Name);
}
示例3: SumbitException
/// <summary>
/// Submit an exception online.
/// </summary>
/// <param name="e">
/// The Exception
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
internal static bool SumbitException(Exception e)
{
var err = e.ToString();
var ass = Assembly.GetCallingAssembly().GetName().Name;
var ver = Assembly.GetCallingAssembly().GetName().Version.ToString();
var st = new StackTrace().GetFrame(1);
var name = st.GetMethod().ReflectedType.FullName + st.GetMethod().Name;
return SendPost(err, ass, ver, name);
}
示例4: Write
/// <summary>
/// Writes the specified log level.
/// </summary>
/// <param name="logLevel">Used level.</param>
/// <param name="msg">Message.</param>
/// <param name="exception">The exception (or null).</param>
public override void Write(LogLevel logLevel, string msg, Exception exception)
{
var frame = new StackTrace(SkipFrameCount).GetFrame(0);
var caller = frame.GetMethod().ReflectedType.Name + "." +
frame.GetMethod().Name + "():" + frame.GetFileLineNumber();
System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + caller.PadRight(50) + logLevel.ToString().PadRight(10) + msg);
if (exception != null)
System.Diagnostics.Debug.WriteLine(BuildExceptionDetails(exception, 4));
}
示例5: Write
/// <summary>
/// Writes the specified log level.
/// </summary>
/// <param name="logLevel">Used level.</param>
/// <param name="msg">Message.</param>
/// <param name="exception">The exception (or null).</param>
public override void Write(LogLevel logLevel, string msg, Exception exception)
{
var frame = new StackTrace(SkipFrameCount).GetFrame(0);
var caller = frame.GetMethod().ReflectedType.Name + "." +
frame.GetMethod().Name + "():" + frame.GetFileLineNumber();
ConsoleColor color = Console.ForegroundColor;
Console.ForegroundColor= GetColor(logLevel);
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + caller.PadRight(50) + logLevel.ToString().PadRight(10) + msg);
if (exception != null)
Console.WriteLine(BuildExceptionDetails(exception, 4));
Console.ForegroundColor = color;
}
示例6: WriteError
/// <summary>
/// Prints a red, error line of log, together with timestamp and method name.
/// </summary>
/// <param name="logText">The log line to be printed.</param>
public static void WriteError(string logText)
{
DateTime _DTN = DateTime.Now;
StackFrame _SF = new StackTrace().GetFrame(1);
Console.Write("[" + _DTN.ToLongTimeString() + ":" + _DTN.Millisecond.ToString() + "] [");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(_SF.GetMethod().ReflectedType.Name + "." + _SF.GetMethod().Name);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("] » ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(logText);
Console.ForegroundColor = ConsoleColor.Gray;
}
示例7: SPDException
/// <summary>
/// Initializes a new instance of the <see cref="SPDException"/> class.
/// </summary>
/// <param name="inner">The inner.</param>
/// <param name="message">The message.</param>
/// <param name="url">The URL.</param>
public SPDException(Exception inner, string message, string url)
: base(message, inner)
{
StackFrame frame = new System.Diagnostics.StackTrace(true).GetFrame(1);
this.where = "File: " + frame.GetFileName() + Environment.NewLine + "Method: " + frame.GetMethod().Name + Environment.NewLine + "Line: " + frame.GetFileLineNumber() + Environment.NewLine + "Col: " + frame.GetFileColumnNumber();
this.url = url;
}
示例8: ThisMethod
public static String ThisMethod()
{
StackFrame sf = new StackTrace().GetFrame(1);
MethodBase method = sf.GetMethod();
String sep = ( method.IsStatic ? "::" : "." );
return String.Format( "{0}{1}{2}$ ", method.DeclaringType.Name, sep, method.Name);
}
示例9: GetCallingType
public static Type GetCallingType()
{
if (EnvironmentHelper.IsProcessHostedByTool)
{
return typeof(object);
}
//#if NETFX_CORE
// var type = typeof(object);
//#else
// var stackTrace = StackTraceHelper.GetStackTrace();
// var stackFrame = stackTrace.GetFrame(2);
// var type = stackFrame.GetMethod().DeclaringType;
//#endif
#if NET
var frame = new StackFrame(2, false);
var type = frame.GetMethod().DeclaringType;
#elif NETFX_CORE
var type = typeof(object);
#else
var frame = new StackTrace().GetFrame(2);
var type = frame.GetMethod().DeclaringType;
#endif
return type;
}
示例10: Log
public void Log(string type, string message, LogLevel level)
{
string msg = message;
if (!string.IsNullOrWhiteSpace(type)) msg = string.Format("[{0}]{1}", type, message);
if (level == LogLevel.Debug)
{
StackFrame x = new StackTrace(true).GetFrame(1);
string MethodName = x.GetMethod().Name;
string Filename = x.GetFileName();
int Line = x.GetFileLineNumber();
msg = string.Format("[{0,-3}]{1,-12}:{2,-4} {3}",
MethodName,
Filename,
Line,
msg);
}
TDebugInfo db = new TDebugInfo()
{
Level = level,
Text = msg,
};
if (this.OnLog != null)
{
OnLog(this, new LogArgs() { DebugInfo = db });
}
}
示例11: executeShell
private static String executeShell()
{
PlatformID currentPlatform = Environment.OSVersion.Platform;
var stackFrame = new StackTrace(1).GetFrame(0);
var method = stackFrame.GetMethod();
var shellCmdAttr = method.GetCustomAttributes(typeof(ShellCmdAttribute), false)
.Cast<ShellCmdAttribute>()
.Where(t => t.PlatformID == currentPlatform).FirstOrDefault();
if (shellCmdAttr == null)
return null;
String programName = shellCmdAttr.Program;
String arguments = shellCmdAttr.Arguments;
var process = new Process();
var psi = process.StartInfo;
psi.FileName = programName;
psi.Arguments = arguments;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
process.Start();
var content = process.StandardOutput.ReadToEnd();
process.WaitForExit();
var match = shellCmdAttr.Regex.Match(content);
if (match == null || !match.Success)
return null;
var value = match.Groups["value"].Value;
return value;
}
示例12: OnCheckboxStateChange
protected override void OnCheckboxStateChange(bool state) {
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackTrace().GetFrame(0);
Debug.Log("{0}.{1}() method called.".Inject(GetType(), stackFrame.GetMethod().Name));
// UNDONE
// playerPrefsMgr.IsPauseOnLoadEnabled = state;
// Debug.LogWarning("OnPauseAfterReloadOptionChange() is not yet fully implemented.");
}
示例13: LogMethodException
public static void LogMethodException(
string exception,
LOGSEVERITY eSeverity = LOGSEVERITY.Error)
{
var sf = new StackTrace(true).GetFrame(1);
var method = sf.GetMethod();
Log(string.Format("Got exception = {0}!", exception), eSeverity, method.Name, sf.GetFileLineNumber(), method.ReflectedType.Name);
}
示例14: GenerateExceptionTest
internal static void GenerateExceptionTest(this Exception ex)
{
var sb = new StringBuilder();
GenerateExceptionTest(ex, 0, sb);
var trace = new StackTrace().GetFrame(1);
File.WriteAllText(@"d:\" + trace.GetMethod().Name, sb.ToString());
}
示例15: Error
public static void Error(string format, params object[] pParams)
{
var frame = new StackTrace().GetFrame(1);
var final = string.Format("[{0}] - {1}:{2} - ", DateTime.Now, frame.GetMethod().ReflectedType.FullName, frame.GetMethod().Name);
lock (_oLock)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
_textWriter.Write(final);
Console.ForegroundColor = ConsoleColor.Red;
_textWriter.WriteLine(format, pParams);
// _streamWriter.Write(final);
// _streamWriter.WriteLine(format, pParams);
// _streamWriter.Flush();
_textWriter.Flush();
}
}