C#中错误日志记录方法,信息比较详细易定位

C#中错误日志记录方法,信息比较详细易定位

2017年06月06日 11:39:13 smartsmile2012 阅读数 2218

 版权声明:本文为博主原创文章,未经博主允许不得转载,如文章对您有帮助,请页面左侧随意打赏。 https://blog.csdn.net/smartsmile2012/article/details/72876577


 
  1. namespace Sample3

  2. {

  3. class Program

  4. {

  5. static void Main(string[] args)

  6. {

  7. try

  8. {

  9. int i = Convert.ToInt32("a");

  10. }

  11. catch (Exception)

  12. {

  13. TraceMessage("Something happened.");

  14. }

  15. Console.ReadLine();

  16. }

  17.  
  18. private static void TraceMessage(string message,

  19. [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",

  20. [CallerFilePath] string sourceFilePath = "",

  21. [CallerLineNumber] int sourceLineNumber = 0)

  22. {

  23. Console.WriteLine("message: " + message);

  24. Console.WriteLine("member name: " + memberName);

  25. Console.WriteLine("source file path: " + sourceFilePath);

  26. Console.WriteLine("source line number: " + sourceLineNumber);

  27. }

  28. }

  29. }

原文地址:https://www.cnblogs.com/grj001/p/12224625.html