本文整理汇总了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);
}
示例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();
}
示例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;
}
示例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
}
示例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);
}
示例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());
}
示例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());
}
示例8: GetStackTrace
public static string GetStackTrace()
{
var stackTrace = new StackTrace(true);
return stackTrace.ToString();
//return stackTraceGetter.Invoke();
}
示例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);
}
示例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());
}
}
示例11: CompoundMemento
protected CompoundMemento()
{
if (CaptureStackTrace)
{
var stackTrace = new StackTrace(true);
StackTrace = stackTrace.ToString();
}
}
示例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);
}
示例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);
}
示例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() );
}
}
示例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;
}