C# 除錯(DEBUG)專用LOG函數 [顯示檔案/行數/函數 等相關位置]
C# 除錯(DEBUG)專用LOG函數 [顯示檔案/行數/函數 等相關位置]
資料來源: https://dotblogs.com.tw/yc421206/2010/10/24/18546
https://learn.microsoft.com/zh-tw/dotnet/api/system.diagnostics.stacktrace?view=net-7.0
線上編譯器: https://dotnetfiddle.net/
Code
//C# 6/4.X
using System;
using System.Diagnostics;
public class Program
{
public static void TestMethod()
{
string currentName = new StackTrace(true).GetFrame(0).GetMethod().Name;
string callName = new StackTrace(true).GetFrame(1).GetMethod().Name;
Console.WriteLine("目前行號: " + new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString());
Console.WriteLine("呼叫名稱: " + callName);
Console.WriteLine("目前方法: " + currentName);
}
public static void Main()
{
Console.WriteLine("Hello World");
TestMethod();
}
}
2 thoughts on “C# 除錯(DEBUG)專用LOG函數 [顯示檔案/行數/函數 等相關位置]”
C# online editor
c# online compiler
C# 線上編輯器
C# 線上編譯器
https://www.programiz.com/csharp-programming/online-compiler/
C# online editor
c# online compiler
C# 線上編輯器
C# 線上編譯器
https://dotnetfiddle.net/