当前位置: 首页>>代码示例>>C#>>正文


C# StackTrace.GetMethod方法代码示例

本文整理汇总了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);
        }
开发者ID:johannesg,项目名称:NServiceBus,代码行数:28,代码来源:NServiceBusPerformanceTest.cs

示例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);
 }
开发者ID:huangxuanheng,项目名称:ChooseDishes,代码行数:7,代码来源:Logger.cs

示例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);
 }
开发者ID:TheWicked,项目名称:OCTGN,代码行数:18,代码来源:ErrorReporter.cs

示例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));
        }
开发者ID:nathanmarck,项目名称:Aurora-Sim,代码行数:16,代码来源:SystemDebugLogger.cs

示例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;
        }
开发者ID:nathanmarck,项目名称:Aurora-Sim,代码行数:19,代码来源:ConsoleLogger.cs

示例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;
        }
开发者ID:habb0,项目名称:Holograph-Emulator-Original,代码行数:18,代码来源:Console.cs

示例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;
 }
开发者ID:tgassner,项目名称:SPDPatientDocumentation,代码行数:13,代码来源:SPDExceptions.cs

示例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);
 }
开发者ID:filipek,项目名称:SmartGraph,代码行数:7,代码来源:Diagnostics.cs

示例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;
        }
开发者ID:pars87,项目名称:Catel,代码行数:28,代码来源:StaticHelper.cs

示例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 });
            }
        }
开发者ID:rajeshwarn,项目名称:rasg,代码行数:29,代码来源:SGLLLog.cs

示例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;
        }
开发者ID:HongJunRen,项目名称:Quick.OwinMVC,代码行数:32,代码来源:SystemInfoUtils.cs

示例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.");
    }
开发者ID:Maxii,项目名称:CodeEnv.Master,代码行数:8,代码来源:GuiPauseOnLoadOption.cs

示例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);
 }
开发者ID:huangxuanheng,项目名称:ChooseDishes,代码行数:8,代码来源:Logger.cs

示例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());
        }
开发者ID:xeno-by,项目名称:relinq,代码行数:8,代码来源:RelinqExceptionSupport.cs

示例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();
            }
        }
开发者ID:NitroXenon,项目名称:Ignite,代码行数:18,代码来源:Log.cs


注:本文中的System.Diagnostics.StackTrace.GetMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。