Skip to content

Instantly share code, notes, and snippets.

@rfum
Created January 11, 2018 22:50
Show Gist options
  • Save rfum/be82cc23af835562c334ad75539e7fd2 to your computer and use it in GitHub Desktop.
Save rfum/be82cc23af835562c334ad75539e7fd2 to your computer and use it in GitHub Desktop.
StackTrace C# Örnek
using System;
namespace StackTrace
{
class Program
{
static void Main(string [] args)
{
A();
}
static void A() {B();}
static void B() {C();}
static void C()
{
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true);//stacktrace sınıfından bir obje oluşuturuldu true flagi ile scope data alındı
int lineNumber = st.FrameCount;//toplam metod sayısı-threade ait-
for (int i = 0; i < lineNumber; i++)//frameler arası iterasyon
{
Console.WriteLine($"[DosyaAdı] : {st.GetFrame(i).GetFileName()} [MetodAdı] : {st.GetFrame(i).GetMethod().Name} " +
$"[SatırNo] : { st.GetFrame(i).GetFileLineNumber() } [KolonNo] : {st.GetFrame(i).GetFileColumnNumber()}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment