Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I log an exception with a full call stack?
    primarykey
    data
    text
    <p>I want to use ELMAH to log an exception (without throwing it all the way up the call stack) and it log the entire call stack.</p> <p>Example code:</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { DoSomething(); } private void DoSomething() { try { TrySomething(); } catch (Exception ex) { LogException(ex); } } private void TrySomething() { throw new NotImplementedException(); } public static void LogException(Exception ex) { var currentStack = new System.Diagnostics.StackTrace(true); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } </code></pre> <p>Now, within the LogException method I can see the call stack telling me DoSomething() called TrySomething(), and that threw the exception, but I can't see the call stack showing me Page_Load() called DoSomething(). I want to be able to see the full calling stack.</p> <p>Example of what ex.StackTrace looks like inside LogException method:</p> <pre><code>at WebApplication1._Default.TrySomething() in C:\Projects\test\GeneralTests\WebApplication1\Default.aspx.cs:line 26 at WebApplication1._Default.DoSomething() in C:\Projects\test\GeneralTests\WebApplication1\Default.aspx.cs:line 20 </code></pre> <p>I can get the full call stack from System.Diagnostics.StackTrace(), for example:</p> <pre><code>at WebApplication1._Default.LogException(Exception ex) at WebApplication1._Default.DoSomething() at WebApplication1._Default.Page_Load(Object sender, EventArgs e) [snip] </code></pre> <p>(and I can get line numbers and source file details by walking each frame of StackTrace)</p> <p>But how do I inject this into the Exception or raise a new Exception with this call stack detail? Is there an elegant way to do this? Have I missed something really obvious?!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload