C# - How to get Class Name and Line Number when an Exception is called
<p>I need two methods, one for getting the Class from where the exception was called, and another one which gets the line number where an exception was called.</p>

<p>So far I have this code, which gets me the Class Name and Line Number together (example: DatabaseHandler.cs:line 70):</p>

<pre><code>    private string GetClassAndLine()
    {
        string tempName = e.GetBaseException().ToString();
        int tempPosition = 0;
        int length = tempName.Length;
        for (int i = 0; i &lt; length; i++)
        {
            if (tempName.ElementAt(i).Equals('\\'))
            {
                tempPosition = i + 1;
            }
        }
        return tempName.Substring(tempPosition, length - tempPosition);
    }
</code></pre>

<p>So if you have any ideas how I could get them individually, it would be of great help. These are then passed into Oracle to store any exceptions which occur.</p>

<p>Update 2:</p>

<p>I am currently testing this code, as some suggested:</p>

<pre><code>        private string GetClassName()
    {
        System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true); 
        return trace.GetFrame(0).GetMethod().ReflectedType.FullName;
    }

    private int GetLineNumber()
    {
        System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true); 
        return trace.GetFrame(0).GetFileLineNumber();
    }
</code></pre>

<p>This is what was returned at a particular Database Exception. No Line Number or Class Name where it was triggered. How can I get that?</p>

<pre><code>    Error was found at Class: Oracle.DataAccess.Client.OracleException.     
    Line Number: 0
</code></pre>

<p>What I want is for Example: "Class: Logging.cs, Line: 57" </p>

<p>Thanks, 
Ryan</p>
