C# Program to Get Current Stack Trace Information Using Environment Class
Last Updated :
21 Nov, 2021
In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. By just using some predefined methods we can get the information of the Operating System using the Environment class. Here in this article, we are using the StackTrace property to get the current stack trace information. This property is used to get the current stack trace information
Syntax:
string Environment.StackTrace
Return: string and gives the class name along with id
Example 1:
C#
using System;
class GFG{
static public void Main()
{
string my_variable = "Hello Geeks" ;
my_variable = Environment.StackTrace;
Console.WriteLine( "Information of current stack trace: \n" +
my_variable);
}
}
|
Output:
Current Stack Trace Details:
at System.Environment.get_StackTrace () [0x00000] in <a1ae6166591d4020b810288d19af38d4>:0
at GFG.Main () [0x00000] in <ec0c23afce674aedba9f00d218402cf6>:0
Example 2:
C#
using System;
class GFG{
static public void Main()
{
string my_variable = "58" ;
my_variable = Environment.StackTrace;
Console.WriteLine( "Information of current stack trace: \n" +
my_variable);
}
}
|
Output:
Current Stack Trace Details:
at System.Environment.get_StackTrace () [0x00000] in <a1ae6166591d4020b810288d19af38d4>:0
at GFG.Main () [0x00000] in <092e5ea1577d4af6be34040e9472afab>:0
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...