title: Strategy for logging in production for Dynamics CRM plugins
body: <p>CRM 2011 on premise.</p>
  
  <p>I have a plugin written in C#. It could throw exceptions or otherwise behave badly in production.</p>
  
  <p>When this happens I want to capture information about the state and about recent code execution to help me analyse the problem.</p>
  
  <p>Ideally I would like the following:</p>
  
  <ol>
  <li><p>If the code decides I should know about a problem then I want it to be able to tell me that there was a problem asap, without me looking to see if a problem has occurred.</p></li>
  <li><p>I want the information about the problem to be easily accessible to me. I don't want to have to RDP to another machine and search through files.</p></li>
  <li><p>I don't want logging to have much impact on performance.</p></li>
  </ol>
  
  <p>I guess I'm looking for something like this:  </p>
  
  <ul>
  <li>Retention of last n lines of log in memory.</li>
  <li>A single function call to add a line to the log.</li>
  <li>A single function call to cause an error to be recorded.</li>
  <li>When there's an error, email to me saying there was a problem. This contains summary info.</li>
  <li>The email contains a link to a web page showing me full error details. Stack trace, error message, date, time, user etc, last n lines of log.</li>
  <li>It'd be nice if there was also a web page somewhere showing me all errors, with filtering, sorting and so on.</li>
  </ul>
  
  <p>I'm fairly new to CRM but I've developed systems like this before. Since CRM has been around for many years I'd expect this to be available for it.</p>