title: How to map a thrown exception to an event ID for logging?
body: <p>In our code base, an error condition may cause an exception to be thrown. Somewhere else in the code an exception handler catches the exception and logs the error to the Windows Event log.</p>
  
  <p>When the error is detected and the exception is thrown is where we have the most information about the error condition and I'd like to identify the error with a unique event ID that will be logged in the windows event log.</p>
  
  <p>What is the best way to include this event ID in the exception that is thrown?</p>
  
  <p>I thought about using <a href="http://msdn.microsoft.com/en-us/library/system.exception.hresult%28v=vs.100%29.aspx" rel="nofollow">Exception.HResult</a>, but that seems intended to be used for COM/win32 interop.  Do people use <a href="http://en.wikipedia.org/wiki/HRESULT" rel="nofollow">HResult</a> for this purpose?  It seems one could map severity to the loglevel, the facility code to the Event source, and the Hresult code to an Event ID. Is this a common approach?</p>
  
  <p>I thought about using the <a href="http://msdn.microsoft.com/en-us/library/system.exception.data%28v=vs.100%29.aspx" rel="nofollow">Exception.Data</a> dictionary and adding a named "EventID" value to the thrown exception so my handler can use that value to log the EventID.</p>
  
  <p>Anyone have any good advice or suggestions?</p>