title: Writing stack trace to log file only when exception thrown
body: <p>I want to write the stack trace only when I have exceptions, currently I do it like this </p>
  
  <pre><code> layout="${longdate}|${level}|${message} ${exception:format=tostring} | ${stacktrace}"
  </code></pre>
  
  <p>So I always get it in my log file.</p>
  
  <p>EDIT:</p>
  
  <p>I use this layout for all my logging, so when I dont have any exceptions I also get the stack trace.But I need it only when i have some exception</p>
  
  <p>when I have an exception I have following output, and it what I need </p>
  
  <pre><code>2011-07-01 22:59:02.3782|Debug|fffffffffffffffffffffffffffff System.Exception: Exception of type 'System.Exception' was thrown. | AppDomain.ExecuteAssembly =&gt; AppDomain._nExecuteAssembly =&gt; Program.Main
  </code></pre>
  
  <p>But without exception :</p>
  
  <pre><code>2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff  | AppDomain.ExecuteAssembly =&gt; AppDomain._nExecuteAssembly =&gt; Program.Main
  </code></pre>
  
  <p>But I want only</p>
  
  <pre><code>2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff
  </code></pre>
  
  <p>Need ideas how to do so...</p>