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


C# Diagnostics.StackTrace类代码示例

本文整理汇总了C#中System.Diagnostics.StackTrace的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.StackTrace类的具体用法?C# System.Diagnostics.StackTrace怎么用?C# System.Diagnostics.StackTrace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.Diagnostics.StackTrace类属于命名空间,在下文中一共展示了System.Diagnostics.StackTrace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Siege

 /// <summary>
 /// Initializes a new instance of Siege client
 /// </summary>
 /// <param name="name">Name.</param>
 /// <param name="tags">Tags.</param>
 public Siege(string name = null, params string[] tags)
 {
     this.server = Module.Find<SiegeServer>();
     this.Name = name;
     this.Tags = new ReadOnlyCollection<string>(tags);
     creatorStackTrace = Diagnostic.GetStackTrace(1);
 }
开发者ID:TinnapopSonporm,项目名称:SinozeEngineBird,代码行数:12,代码来源:Siege.cs

示例2: LogFunc

        static void LogFunc(string logDomain, GLib.LogLevelFlags logLevel, string message)
        {
            System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (2, true);
            string msg = string.Format ("{0}-{1}: {2}\nStack trace: {3}{4}",
                logDomain, logLevel, message, Environment.NewLine, trace.ToString ());

            switch (logLevel) {
            case GLib.LogLevelFlags.Debug:
                Log.Debug (msg);
                break;
            case GLib.LogLevelFlags.Info:
                Log.Info (msg);
                break;
            case GLib.LogLevelFlags.Warning:
                Log.Warn (msg);
                break;
            case GLib.LogLevelFlags.Error:
                Log.Error (msg);
                break;
            case GLib.LogLevelFlags.Critical:
            default:
                Log.Fatal (msg);
                break;
            }
        }
开发者ID:titobrasolin,项目名称:StrongMonkey,代码行数:25,代码来源:GLibLogging.cs

示例3: Parse

        /// <summary>
        /// Public scanner method. Test scanner input for this parser's patterns.
        /// </summary>
        /// <remarks>Most parsers won't need to override this method</remarks>
        /// <param name="scan">Scanner to parse from</param>
        /// <returns>Match (success of failure) of the parser against the scanne</returns>
        public virtual ParserMatch Parse(IScanner scan)
        {
            scan.Normalise();

            var st = new System.Diagnostics.StackTrace();
            scan.StackStats(st.FrameCount);

            if (scan.RecursionCheck(this, scan.Offset))
                if (!(this is Recursion))
                    return scan.NoMatch;

            ParserMatch m;

            if (this is IMatchingParser) m = ((IMatchingParser) this).TryMatch(scan);
            else m = Parse(scan);

            if (m.Success)
            {
                scan.ClearFailures();
            }
            else
            {
                scan.AddFailure(this, scan.Offset);
            }
            return m;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:32,代码来源:Parser.cs

示例4: DisplayForm

        public static void DisplayForm(params string[] testSteps)
        {
            using (ManualTestForm form = new ManualTestForm())
            {
                int i = 0;
                Console.WriteLine("Steps:");
                foreach (string step in testSteps)
                {
                    string message = String.Format("{0} {1}", i, step);
                    Console.WriteLine(message);
                    form.TestStepList.Items.Add(message);
                    ++i;
                }
                System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(1);
                form.Text = trace.GetFrame(0).GetMethod().DeclaringType.FullName
                    + trace.GetFrame(0).GetMethod().Name;

                DialogResult result = form.ShowDialog();

                // dumping comments
                Console.WriteLine("Manual Test");
                Console.WriteLine(form.Comments);

                Console.WriteLine("Success: {0}", result);
                Assert.AreEqual(result, DialogResult.Yes,
                    "Manual Test failed");
            }
        }
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:28,代码来源:ManualTester.cs

示例5: GetStamp

        /*
         * Gets a stamp for debug messages that contains the time and the calling method.
         *
         * The calling method is judged to be the lowest frame in the stack that's
         * *not* in the FLog class. If depth is set, we will walk further up the
         * stack.
         */
        public static string GetStamp(int extraDepth=0)
        {
            string rv = "";
            System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace();

            // Walk up the stack to the first frame that's *not* in this class (i.e., the lowest caller) and append it.
            System.Diagnostics.StackFrame sf = null;
            int i = 0;
            for ( ; i<trace.FrameCount; i++) {
            sf = trace.GetFrame(i);
            if (sf.GetMethod().DeclaringType != typeof(FLog))
                break;
            }

            // Walk up some extra frames as needed.
            i += extraDepth;

            sf = trace.GetFrame(i);
            if (sf != null) {
            string m = sf.GetMethod().DeclaringType.ToString();
            rv += System.String.Format("{0}:{1}.{2}", Time.realtimeSinceStartup.ToString("F1"), m, sf.GetMethod().Name);
            } else {
            rv = Time.realtimeSinceStartup.ToString("F1");
            }
            return rv;
        }
开发者ID:joshleejosh,项目名称:filutil,代码行数:33,代码来源:FLog.cs

示例6: Log

        public static void Log(string message, bool writeToConsole = true)
        {
            if (message == null) return;
            string assembly = "";
            try
            {
                System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();

                if (stackTrace.FrameCount != 0)
                    assembly = stackTrace.GetFrame(1).GetMethod().DeclaringType.Assembly.GetName().Name;

                if ((assembly.StartsWith("Rocket.") || assembly == "Assembly-CSharp" || assembly == "UnityEngine") && stackTrace.FrameCount > 2)
                {
                    assembly = stackTrace.GetFrame(2).GetMethod().DeclaringType.Assembly.GetName().Name;
                }
                if (assembly == "" || assembly == typeof(Logger).Assembly.GetName().Name || assembly == lastAssembly || assembly.StartsWith("Rocket.") || assembly == "Assembly-CSharp" || assembly == "UnityEngine")
                {
                    assembly = "";
                }
                else
                {
                    assembly = assembly + " >> ";
                }

                lastAssembly = assembly;
                message = assembly + message;
            }
            catch (Exception)
            {
                throw;
            }
            ProcessInternalLog(ELogType.Info, message, writeToConsole);
        }
开发者ID:cartman-2000,项目名称:Rocket,代码行数:33,代码来源:Logger.cs

示例7: Open

        /// <summary>
        ///     Opens the specified filename
        /// </summary>
        protected void Open(string filename, string fileMode)
        {
            // sanity check
            if (IsOpen)
            {
                throw new ApplicationException("ERROR: The Open method was called even though the file is already open.");
            }

            FileStreamPointer = SafeNativeMethods.gzopen(filename, fileMode);

            if (FileStreamPointer == IntPtr.Zero)
            {
                //for some reason throwing an exception here can hang. Possibly from the managed to native transition?
                //if you encounter that you should check for the complicating condition before trying to open the gzip file and handle it accordingly
                //you may have to call Environment.Exit(-1) as throwing an exception may hang
                //interestingly enabling native code debugging is a workaround but that won't work outside Visual Studio
                Console.Error.WriteLine(string.Format("ERROR: Unable to open the file ({0}) for reading", filename));
                Console.Error.WriteLine("This process will now exit");
                System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
                Console.Error.WriteLine(t.ToString());
                System.Environment.Exit(-1);
            }

            FilePath = filename;
            IsOpen = true;
            CurrentOffset = 0;
            BufferOffset = 0;
        }
开发者ID:abladon,项目名称:canvas,代码行数:31,代码来源:GzipCommon.cs

示例8: Message

        public Message()
        {
            TypeLog = Enums.TypeLog.Error;
            Thread = string.Format(", CurrentThreadName:{0}, CurrentThreadManagedThreadId:{1}, CurrentThreadCurrentCulture:{2}, CurrentThreadPriority:{3}",
                System.Threading.Thread.CurrentContext,
                System.Threading.Thread.CurrentThread.Name,
                System.Threading.Thread.CurrentThread.ManagedThreadId,
                System.Threading.Thread.CurrentThread.CurrentCulture,
                System.Threading.Thread.CurrentThread.Priority);
            Domain = Environment.UserDomainName;
            Username = Environment.UserName;
            Hostname = Environment.MachineName;
            try
            {
                Ips = string.Join(", ", Dns.GetHostEntry(Dns.GetHostName()).AddressList.Select(ip => ip.ToString()));
            }
            catch (Exception ex)
            { }

            System.Diagnostics.StackTrace stack = new System.Diagnostics.StackTrace();
            ApplicationMode = Params.ApplicationMode;

            Stacktrace = string.Empty;
            foreach (var item in stack.GetFrames())
            {
                Stacktrace += string.Format("{0}: Class: {1}; Method: {2}; Line: {3}; Collumn: {4}; \r\n", item.GetFileName(), item.GetMethod().DeclaringType.FullName,
                        item.GetMethod().Name, item.GetFileLineNumber(), item.GetFileColumnNumber());
            }
        }
开发者ID:rodvieirasilva,项目名称:Compiler-With-Fuzzy,代码行数:29,代码来源:Message.cs

示例9: ExceptionDispatchInfo

        private ExceptionDispatchInfo(Exception exception)
        {
            // Copy over the details we need to save.
            m_Exception = exception;
#if MONO
			var count = exception.captured_traces == null ? 0 : exception.captured_traces.Length;
			var stack_traces = new System.Diagnostics.StackTrace [count + 1];
			if (count != 0)
				Array.Copy (exception.captured_traces, 0, stack_traces, 0, count);

			stack_traces [count] = new System.Diagnostics.StackTrace (exception, 0, true);
			m_stackTrace = stack_traces;
#else
            m_remoteStackTrace = exception.RemoteStackTrace;
            
            // NOTE: don't be tempted to pass the fields for the out params; the containing object
            //       might be relocated during the call so the pointers will no longer be valid.
            object stackTrace;
            object dynamicMethods;
            m_Exception.GetStackTracesDeepCopy(out stackTrace, out dynamicMethods);
            m_stackTrace = stackTrace;
            m_dynamicMethods = dynamicMethods;

            m_IPForWatsonBuckets = exception.IPForWatsonBuckets;
            m_WatsonBuckets = exception.WatsonBuckets;                                                        
#endif
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:27,代码来源:exceptionservicescommon.cs

示例10: TypeCache

        //------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Constructors
        //------------------------------------------------------------------------------------------------------------------------
        static TypeCache()
        {
#if NETFX
            //add entry assembly
            var EntryAssembly = Assembly.GetEntryAssembly();
            if (EntryAssembly != null)
                EntryAssemblies.Add(EntryAssembly);

            //Add as many assemblies as we can
            //add from stack
            try
            {
                var frameAssemblies = new System.Diagnostics.StackTrace().GetFrames().Select(t => t.GetMethod().Module.Assembly).ToHashSet();
                foreach (var entry in frameAssemblies)
                    EntryAssemblies.Add(entry);
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception during Stack Frame assembly examination"); }

            //add from domain
            try
            {
                EntryAssemblies.AddFromSource(AppDomain.CurrentDomain.GetAssemblies());
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception during AppDomain assembly examination"); }
#elif UNIVERSAL
            EntryAssemblies.Add(Windows.UI.Xaml.Application.Current.GetType().GetTypeInfo().Assembly);
#endif
        }
开发者ID:yodiwo,项目名称:plegma,代码行数:34,代码来源:TypeCache.cs

示例11: HealthCheck

 public static void HealthCheck(Action healthyBehaviour)
 {
     var currentStack = new System.Diagnostics.StackTrace();
     Application.Current.Dispatcher.BeginInvoke((Action)delegate
     {
         try
         {
             foreach (var server in SERVERS)
                 server.ok = false;
             checkServers();
             int attempts = 0;
             const int MILIS_BETWEEN_TRIES = 500;
             var timer = new DispatcherTimer(TimeSpan.FromMilliseconds(MILIS_BETWEEN_TRIES), DispatcherPriority.Normal,
             (sender, args) =>
             {
                 var brokenServers = SERVERS.Where(s => !s.ok);
                 attempts++;
                 if (brokenServers.Count() == 0)
                 {
                     self.Visibility = Visibility.Collapsed;
                     ((DispatcherTimer)sender).Stop();
                     healthyBehaviour();
                 }
             }, Application.Current.Dispatcher);
             timer.Start();
         }
         catch (Exception e)
         {
             throw new Exception(currentStack.ToString(), e);
         }
     });
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:32,代码来源:ProviderMonitor.xaml.cs

示例12: LogFunc

		static void LogFunc (string logDomain, GLib.LogLevelFlags logLevel, string message)
		{
			if (RemainingBytes < 0)
				return;

			System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (2, true);
			string msg = string.Format ("{0}-{1}: {2}\nStack trace: \n{3}", 
			    logDomain, logLevel, message, trace.ToString ());

			switch (logLevel) {
			case GLib.LogLevelFlags.Debug:
				LoggingService.LogDebug (msg);
				break;
			case GLib.LogLevelFlags.Info:
				LoggingService.LogInfo (msg);
				break;
			case GLib.LogLevelFlags.Warning:
				LoggingService.LogWarning (msg);
				break;
			case GLib.LogLevelFlags.Error:
			case GLib.LogLevelFlags.Critical:
			default:
				LoggingService.LogError (msg);
				break;
			}
			
			RemainingBytes -= msg.Length;
			if (RemainingBytes < 0)
				LoggingService.LogError ("Disabling glib logging for the rest of the session");
		}
开发者ID:kthguru,项目名称:monodevelop,代码行数:30,代码来源:GLibLogging.cs

示例13: append

        public static bool append(String message, MessageType mt)
        {
            try
            {
                // get name of calling module and function
                System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
                System.Reflection.MethodBase mb = stackTrace.GetFrame(0).GetMethod(); // =this function
                String name = mb.Name;
                for(int i = 1; i < stackTrace.FrameCount; i++)
                {
                    mb = stackTrace.GetFrame(i).GetMethod();
                    if(mb.Name != name)
                        break;
                }

                //Build and then write the (CSV formatted) line to todays log file
                String logName = getLogName();
                String dateStamp = DateTime.Today.ToString("yyyyMMdd");
                String timeStamp = DateTime.Now.ToString("HH:mm:ss.fff");
                String line = String.Format("{0},{1},{2},{3},{4},\"{5}\"{6}", dateStamp, timeStamp, mb.Module, mb.Name, mt.ToString(), message.Replace(',',';').Replace('"','\''), Environment.NewLine);
                System.IO.File.AppendAllText(logName, line);
            }
            catch(Exception ex)
            {
                // Log errors for testing, but ignore when live
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return false;
            }
            return true;
        }
开发者ID:cbinding,项目名称:stellar,代码行数:30,代码来源:Log.cs

示例14: Error

        /// <summary>
        /// To Log exception informations
        /// Stream witer is replaced with enterprise library
        /// </summary>
        /// <param name="ex"></param>
        public static void Error(string message, Exception ex)
        {
            LogEntry logEntry = null;
            try
            {
                logEntry = new LogEntry();

                logEntry.Categories.Clear();
                logEntry.TimeStamp = DateTime.Now;
                logEntry.Severity = System.Diagnostics.TraceEventType.Error;
                logEntry.Message = message;
                logEntry.Categories.Add("General Category");
                Logger.Write(logEntry);
                System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
                Logger.Write("Method: " + trace.GetFrame(trace.FrameCount - 1).GetMethod().Name);
                Logger.Write("Line: " + trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber());
                Logger.Write("Column: " + trace.GetFrame(trace.FrameCount - 1).GetFileColumnNumber());
            }
            catch
            {
                throw;
            }
            finally
            {
                logEntry = null;
            }
        }
开发者ID:shyam2293,项目名称:spencers,代码行数:32,代码来源:SpencerLogger.cs

示例15: FMEJobManager

        public FMEJobManager()
        {
            try
              {
            //  Let the User know that the FME Session is being established.
            if (ProcessMessage != null)
            {
              ProcessMessage("      - Opening the FME Session in which the specified FME Job will be run...");

            }

            //  Attempt to instantiate the FME Session.
            //  Initiate an FME Session.
            _fmeSession = Safe.FMEObjects.FMEObjects.CreateSession();
            _fmeSession.Init(null);

            //  Exit this method.
            return;

              }
              catch (Safe.FMEObjects.FMEOException fmeException)
              {
            //  Determine the Line Number from which the exception was thrown.
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, true);
            System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);
            int lineNumber = stackFrame.GetFileLineNumber();

            //  Let the User know that the Session Could not be created.
            if (ErrorMessage != null)
            {
              ErrorMessage("");
              ErrorMessage("");
              ErrorMessage("Failed to open the FME Session with error - " + fmeException.FmeErrorMessage + " (Line:  " + lineNumber.ToString() + ")!");
            }

            //  Exit this method.
            return;

              }
              catch (System.Exception caught)
              {
            //  Determine the Line Number from which the exception was thrown.
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true);
            System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);
            int lineNumber = stackFrame.GetFileLineNumber();

            //  Let the User know that the Session Could not be created.
            if (ErrorMessage != null)
            {
              ErrorMessage("");
              ErrorMessage("");
              ErrorMessage("Failed to open the FME Session with error - " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
            }

            //  Exit this method.
            return;

              }
        }
开发者ID:MitchVan,项目名称:DataMaintenanceUtilities,代码行数:59,代码来源:FMEJobManager.cs


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