I have realized that now I’m getting short stacktrace for exceptions in my app.
E.g. I have a simple app:
private static void Main(string[] args)
{
var downloader = new DataDownloader("");
}
internal class DataDownloader
{
public DataDownloader(string template)
{
this._urlTemplate = template;
var manager = new FileManager();
manager.MoveFileSync();
}
}
public class FileManager
{
public FileManager()
{
}
public int MoveFileSync()
{
try
{
throw new ArgumentException();
}
catch (Exception ex)
{
}
return 0;
}
}
And in catch I got simple StackTrace as
How can I get the full Stacktrace starting from the Main
entry point?
2
TBH not sure why this does happen but you can construct an instance of StackTrace
manually and use it:
try
{
throw new ArgumentException();
}
catch (Exception ex)
{
StackTrace st = new StackTrace(true);
Console.WriteLine(ex.StackTrace);
Console.WriteLine("....");
Console.WriteLine(st);
}
Demo @sharplab.io
From the Exception.StackTrace
docs:
The
StackTrace
property returns the frames of the call stack that originate at the location where the exception was thrown. You can obtain information about additional frames in the call stack by creating a new instance of theSystem.Diagnostics.StackTrace
class and using itsStackTrace.ToString
method.
1