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


C# StackTrace.ToString方法代码示例

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


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

示例1: LogEvent

        public static void LogEvent(string details)
        {
            StackTrace st = new StackTrace();
            // Putting into the string with only current program stack trace
            string stack = st.ToString().Substring(0, st.ToString().IndexOf("   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)") - 2);
            stack = stack.Replace("at", "");
            stack = stack.Replace(" ", "");
            stack = stack.Replace("\r\n", "|");
            // Reversing
            string[] all = stack.Split('|');
            Array.Reverse(all);
            stack = "";
            bool first = true;
            foreach (var s in all)
            {
                if (first == false)
                {
                    stack += "->";
                }
                else
                {
                    first = false;
                }
                stack += s;
            }

            string message = "";
            string currentDate = DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"));
            string currentTime = DateTime.Now.ToString("HH:mm:ss");

            message = currentDate + " " + currentTime + " [" + stack + "] " + details;

            StreamWriter writer = null;

            try
            {
                writer = OpenFile(DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US")));
            }
            catch (Exception e)
            {
                writer = OpenFile(DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US")) + "ERROR");
                message = e.Message;
            }

            try
            {
                writer.WriteLine(message);
            }
            catch (Exception e)
            {
                writer.Close();

                writer = new StreamWriter("ERROR.log", true);
                writer.WriteLine(message);
            }

            CloseFile(writer);
        }
开发者ID:DenysPolitiuk,项目名称:SET,代码行数:58,代码来源:Logger.cs

示例2: GetStackTrace

    public static object GetStackTrace()
    {
      var sf = new StackTrace(2, true);
      List<string> newst = new List<string>();
      var sfs = sf.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

      for (int i = 0; i < sfs.Length; i++)
      {
        if (sfs[i].StartsWith(@"   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module)") ||
          sfs[i].StartsWith("   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteCommand(System.String code, IScriptModule module)"))
        {
          break;
        }
        newst.Add(sfs[i].
          Replace("   at #.", string.Empty).
          Replace("   at ", string.Empty).
          Replace("Microsoft.Scripting.CodeContext $context, ", string.Empty).
          Replace("Microsoft.Scripting.CodeContext $context", string.Empty).
          Replace("CodeContext $context, ", string.Empty).
          Replace("CodeContext $context", string.Empty).
          Replace("System.Object ", string.Empty).
          Replace("Object ", string.Empty));
      }

      return newst.ToArray();
    }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:26,代码来源:Exceptions.cs

示例3: LogStackTrace

        internal static void LogStackTrace()
        {
            if (_context != null && _context.Result.Status == TestStatus.Failed)
            {
                var testname = _context.Test.FullName.Split('.')[2].Split('<')[0];
                var methodname = _context.Test.Name;

                var _stackFilePath = string.Format("{0}{1}.cs__{2}()__{3}__StackTrace.txt",
                    _stacktraceDir,
                    testname,
                    methodname,
                    _browser);

                var stackTrace = new StackTrace(true);

                using (var outfile = new StreamWriter(_stackFilePath, false))
                {
                    outfile.WriteLine(_result.Message);
                    outfile.WriteLine("");
                    outfile.WriteLine(stackTrace.ToString());
                }
            }

            _stackTrace = null;
            _context = null;
            _browser = null;
            _result = null;
        }
开发者ID:rohanbaraskar,项目名称:PageObjectFrameworkCSharp,代码行数:28,代码来源:Stacktrace.cs

示例4: Log

	public static void Log(object __message) {
		if (!Debug.isDebugBuild) return;

		// Builds parameters
		System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
		string method = t.ToString().Split('\n')[1];
		method = method.Substring(method.IndexOf("at ") + 3);
		
		string currentFrame = Time.frameCount.ToString("0000000");
		string currentTime = (Time.realtimeSinceStartup * 1000).ToString("00000");
			
		// Finally, composes line
		string fullMessage = "[" + currentFrame + "@" + currentTime + "] " +  method + " :: " + __message;
		//string fullMessage = "[" + currentFrame + ":" + currentTime + " | " +  method + ": " + __message;
		
		// Writes to Unity console log and to normal log
		Debug.Log(fullMessage + "\n");
		System.Console.WriteLine(fullMessage);
		
		//Debug.Log("Flat Mesh Initialized (d)\n"); // UnityEngine.Debug.Log
		//System.Console.WriteLine("Flat Mesh Initialized");
		// Debug.isDebugBuild
		// http://docs.unity3d.com/Documentation/ScriptReference/Application.RegisterLogCallback.html

		
		// Port LoggingFramework:
		// http://forum.unity3d.com/threads/38720-Debug.Log-and-needless-spam

	}
开发者ID:OJ3D,项目名称:unity-tidbits,代码行数:29,代码来源:D.cs

示例5: AssertFailure

     public override AssertFilters  AssertFailure(String condition, String message, 
                               StackTrace location, StackTrace.TraceFormat stackTraceFormat,
                               String windowTitle)
 
     {
         return (AssertFilters) Assert.ShowDefaultAssertDialog (condition, message, location.ToString(stackTraceFormat), windowTitle);
     }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:7,代码来源:AssertFilter.cs

示例6: FRIEND

 internal static void FRIEND(string ns)
 {
     StackTrace trace = new StackTrace();
     string text1 = trace.GetFrame(1).GetMethod().DeclaringType.Namespace;
     string str = trace.GetFrame(2).GetMethod().DeclaringType.Namespace;
     Assert(str.Equals(str) || str.Equals(ns), Environment.GetResourceString("RtType.InvalidCaller"), trace.ToString());
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:7,代码来源:ASSERT.cs

示例7: Show

		public static void Show(Exception e, StackTrace innerStackTrace = null, string customMessage = null)
		{
			var writer = new StringWriter();

			if (customMessage != null)
				WriteCustomMessage(customMessage, writer);
			else
				SetCustomMessageBasedOnTheActualError(writer, e);

			writer.Write("Message: ");
			writer.WriteLine(e.Message);
			if (string.IsNullOrWhiteSpace(UrlUtil.Url) == false)
			{
				writer.Write("Uri: ");
				writer.WriteLine(UrlUtil.Url);
			}
			writer.Write("Server Uri: ");
			writer.WriteLine(GetServerUri(e));

			writer.WriteLine();
			writer.WriteLine("-- Error Information --");
			writer.WriteLine(e.ToString());
			writer.WriteLine();

			if (innerStackTrace != null)
			{
				writer.WriteLine("Inner StackTrace: ");
				writer.WriteLine(innerStackTrace.ToString());
			}
		
			Show(writer.ToString());
		}
开发者ID:925coder,项目名称:ravendb,代码行数:32,代码来源:ErrorPresenter.cs

示例8: GetStackTrace

        public static string GetStackTrace()
        {
            var stackTrace = new StackTrace(true);
            return stackTrace.ToString();

            //return stackTraceGetter.Invoke();
        }
开发者ID:perikete,项目名称:Pulsus,代码行数:7,代码来源:StackTraceHelper.cs

示例9: ER

 public static void ER(Exception e, params string[] extras)
 {
     StackTrace st = new StackTrace();
     StackFrame[] frames = st.GetFrames();
     string methodName = "UnknownMethod";
     for(int i=0;i< frames.Length;i++)
     {
         if (frames[i].GetMethod().Name == System.Reflection.MethodInfo.GetCurrentMethod().Name)
         {
             if (i + 1 < frames.Length)
             {
                 methodName = frames[i + 1].GetMethod().Name;
                 break;
             }
         }
     }
     Console.WriteLine(String.Format("{1}[{4}:{5}][ERROR({2})]{0}:{3}", methodName, tab, Thread.CurrentThread.ManagedThreadId, e.Message, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()));
     Console.WriteLine("==========StackTrace==========");
     if (e.StackTrace != null)
         Console.WriteLine(e.StackTrace.ToString());
     else
         Console.WriteLine(st.ToString());
     Console.WriteLine("=============END==============");
     foreach (string s in extras)
         Console.WriteLine(s);
 }
开发者ID:YoshiEnVerde,项目名称:OCTGN,代码行数:26,代码来源:Logger.cs

示例10: Error

 public static void Error(String msg, Exception ex)
 {
     if (IsEnabled)
     {
         System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex);
         System.Diagnostics.Trace.TraceError(msg + "\r\n" + trace.ToString());
     }
 }
开发者ID:beachead,项目名称:gooey-cms-v2,代码行数:8,代码来源:Logging.cs

示例11: CompoundMemento

 protected CompoundMemento()
 {
     if (CaptureStackTrace)
     {
         var stackTrace = new StackTrace(true);
         StackTrace = stackTrace.ToString();
     }
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:8,代码来源:CompoundMemento.cs

示例12: Show

		public static void Show(Exception e, StackTrace innerStackTrace)
		{
			var details = e +
			              Environment.NewLine + Environment.NewLine +
			              "Inner StackTrace: " + Environment.NewLine +
						  (innerStackTrace == null ? "null" : innerStackTrace.ToString());
			Show(e.Message, details);
		}
开发者ID:richSourceShaper,项目名称:ravendb,代码行数:8,代码来源:ErrorPresenter.cs

示例13: WriteLine

        public static void WriteLine(Exception e)
        {
            string currenttime = DateTime.Now.ToString("[d/M/yyyy HH:mm:ss.fff]");
            string message = currenttime + "  " + e.ToString();
            StackTrace st = new StackTrace(1, true);
            message += st.ToString();

            Trace.TraceError(message);
        }
开发者ID:culiniac,项目名称:quavs,代码行数:9,代码来源:TraceException.cs

示例14: Assert

    public static void Assert( object source, bool condition, string message )
    {
      if( !condition )
      {
        Log.WriteLine( source, "# - " + message );

        StackTrace stackTrace = new StackTrace();
        Log.WriteLine( stackTrace.ToString() );
      }
    }
开发者ID:Torion,项目名称:WpfExToolkit,代码行数:10,代码来源:Log.cs

示例15: OnUnhandledException

        private void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
            StackTrace stackTrace = new StackTrace(args.Exception, true);
            string stackTraceString = args.Exception.StackTrace == null ? stackTrace.ToString() : args.Exception.StackTrace;

            string errText = string.Format("An unhandled exception occurred: {0}\r\nStack Trace: {1}", args.Message, stackTraceString);

            Debug.WriteLine(errText);
            args.Handled = true;
        }
开发者ID:OfficeDev,项目名称:Interop-REST-Mail-Contacts-Calendar-Sample,代码行数:10,代码来源:App.xaml.cs


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