Print stack trace information from C#

前端 未结 5 1363
旧时难觅i
旧时难觅i 2020-12-04 10:27

As part of some error handling in our product, we\'d like to dump some stack trace information. However, we experience that many users will simply take a screenshot of the e

5条回答
  •  攒了一身酷
    2020-12-04 10:59

    Here is the code I use to do this without an exception

    public static void LogStack()
    {
      var trace = new System.Diagnostics.StackTrace();
      foreach (var frame in trace.GetFrames())
      {
        var method = frame.GetMethod();
        if (method.Name.Equals("LogStack")) continue;
        Log.Debug(string.Format("{0}::{1}", 
            method.ReflectedType != null ? method.ReflectedType.Name : string.Empty,
            method.Name));
      }
    }
    

提交回复
热议问题